complete 2083.rs 2530.rs 2721.rs 4128.rs 5584.rs 7512.rs 21519.rs 21964.rs 22862.rs 22973.rs 24123.rs 26993.rs 27514.rs 33849.rs

This commit is contained in:
2026-03-08 23:29:01 +09:00
parent 12445715dd
commit 94591886d6
14 changed files with 899 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
use std::{
cmp::Reverse,
collections::BinaryHeap,
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 n = iter.next().unwrap();
let arr = (0..n)
.map(|_| Reverse(iter.next().unwrap()))
.filter(|x| x.0 != 0)
.collect::<Vec<_>>();
let mut heap = BinaryHeap::from(arr);
while (heap.len() >= 2) {
let a = heap.pop().unwrap().0;
let b = heap.pop().unwrap().0;
if a != b {
heap.push(Reverse(a.max(b)));
} else {
heap.push(Reverse(a + b));
}
}
let res = heap.iter().max().unwrap().0;
println!("{}", res);
}