complete 1370.rs 2499.rs
This commit is contained in:
33
storage/jungol/rs/completed/2499.rs
Normal file
33
storage/jungol/rs/completed/2499.rs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user