complete 9414.rs 17392.rs 26853.rs

This commit is contained in:
2026-01-12 17:59:34 -08:00
parent e24c586ce4
commit 028357635a
3 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<i64>().unwrap());
let n = iter.next().unwrap();
let m = iter.next().unwrap();
let total_expected_happinesses: i64 = (0..n).map(|_| iter.next().unwrap()).sum();
let res = if total_expected_happinesses + n >= m {
0
} else {
let actual_non_happy_day = m - (total_expected_happinesses + n);
let d = actual_non_happy_day / (n + 1);
let remain = actual_non_happy_day % (n + 1);
if remain > 0 {
remain * ((d + 1) * (d + 2) * (2 * d + 3) / 6)
+ (n + 1 - remain) * (d * (d + 1) * (2 * d + 1) / 6)
} else {
(d * (d + 1) * (2 * d + 1) / 6) * (n + 1)
}
};
println!("{}", res);
}

View File

@@ -0,0 +1,36 @@
use std::io::stdin;
fn main() {
let mut lines = stdin().lines();
let line = lines.next().unwrap().unwrap();
let mut iter = line.split(' ').map(|x| x.parse::<usize>().unwrap());
let n = iter.next().unwrap();
let m = iter.next().unwrap();
let words = (0..n)
.map(|_| lines.next().unwrap().unwrap().trim().chars().collect())
.collect::<Vec<Vec<char>>>();
let mut cnts = vec![vec![0; 26]; m];
for i in 0..n {
for (j, &ch) in words[i].iter().enumerate() {
let idx = (ch as u8 - 'a' as u8) as usize;
cnts[j][idx] += 1;
}
}
let mut total_penalty = 0;
for i in 0..m {
let mut max_value = 0;
for j in 0..26 {
let value = cnts[i][j];
if value > max_value {
max_value = value;
}
}
total_penalty += n - max_value;
}
println!("{}", total_penalty);
}

View File

@@ -0,0 +1,53 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let tc = iter.next().unwrap();
const MONEY_LIMIT_U64: u64 = 2_500_000;
const MONEY_LIMIT_F64: f64 = MONEY_LIMIT_U64 as f64;
for _ in 0..tc {
let prices = {
let mut prices = vec![];
let mut value = iter.next().unwrap() as u64;
while value != 0 {
prices.push(value);
value = iter.next().unwrap() as u64;
}
prices.sort();
prices.reverse();
prices
};
let mut flag_expensive = false;
let mut total_price = 0;
for (t, &price) in prices.iter().enumerate() {
let t = t + 1;
let critea = MONEY_LIMIT_F64.powf(1.0 / (t as f64)).ceil() as u64;
if price > critea {
flag_expensive = true;
break;
}
total_price += price.pow(t as u32);
}
if total_price > MONEY_LIMIT_U64 {
flag_expensive = true;
}
if flag_expensive {
println!("Too expensive");
} else {
println!("{}", 2 * total_price);
}
}
}