-
Notifications
You must be signed in to change notification settings - Fork 2
/
dragons_230A_unihernandez22.rs
54 lines (43 loc) · 1.2 KB
/
dragons_230A_unihernandez22.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
43
44
45
46
47
48
49
50
51
52
53
54
use std::cmp::Ordering;
use std::io::stdin;
fn main() {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let words: Vec<i32> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let mut s = words[0];
let n = words[1];
let mut dragons = Vec::<Vec<i32>>::new();
for _ in 0..n {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let words: Vec<i32> = line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let mut dragon = Vec::new();
dragon.push(words[0]);
dragon.push(words[1]);
dragons.push(dragon);
}
dragons.sort_by(|a, b| {
if a.get(0).unwrap() > b.get(0).unwrap() {
return Ordering::Greater;
} else if a.get(0).unwrap() < b.get(0).unwrap() {
return Ordering::Less;
} else {
return Ordering::Equal;
}
});
let mut answer = "YES";
for i in dragons {
if s - i.get(0).unwrap() > 0 {
s += i.get(1).unwrap();
} else {
answer = "NO";
}
}
println!("{}", answer);
}