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);
}