forked from Vicfred/codeforces-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twins.rs
42 lines (30 loc) · 817 Bytes
/
twins.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// https://codeforces.com/problemset/problem/160/A
use std::io;
fn main() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
//let n: i64 = n.trim().parse().unwrap();
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
let mut a: Vec<i64> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
a.sort_by(|x, y| y.cmp(x));
let mut total = 0;
for item in a.clone() {
total += item;
}
let mut mine = 0;
let mut answer = 0;
for item in a {
let twin = total - mine;
if mine > twin {
break;
} else {
mine += item;
answer += 1;
}
}
println!("{}", answer);
}