add cf round-1087-{A,B,C}.rs

This commit is contained in:
2026-03-22 16:28:44 +09:00
parent a42056c8d1
commit 681170f289
3 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
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 t = iter.next().unwrap();
(0..t).for_each(|_| {
let (n, mut c, mut k) = (
// number, combat power, k of flip flop
iter.next().unwrap(),
iter.next().unwrap(),
iter.next().unwrap(),
);
let mut arr = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
arr.sort();
loop {
let key = arr.binary_search(&c);
match key {
Ok(idx) => {
c += arr[idx];
arr.remove(idx);
}
Err(idx) => {
if idx == 0 {
break;
} else {
let delta = c - arr[idx - 1];
let consume = if k >= delta { delta } else { k };
k -= consume;
c += consume + arr[idx - 1];
arr.remove(idx - 1);
}
}
}
}
println!("{}", c);
});
}