complete 1370.rs 2499.rs

This commit is contained in:
2026-07-20 19:01:13 +09:00
parent 0a52264f6c
commit 5b49d47300
2 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
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 n = iter.next().unwrap();
let weights = {
let mut v = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
v.sort();
v
};
// we can make the range [min(S), sum(S)]
let mut res = 0;
let mut cum = 0;
for &w in weights.iter() {
if cum + 1 < w {
res = cum + 1;
break;
}
cum += w;
}
if res == 0 {
res = cum + 1;
}
println!("{}", res);
}