-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Dragons.cpp
More file actions
55 lines (48 loc) · 1.22 KB
/
A_Dragons.cpp
File metadata and controls
55 lines (48 loc) · 1.22 KB
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
55
/*#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
vector<pair<int, int>> dragons(n);
for (int i = 0; i < n; i++) {
cin >> dragons[i].first >> dragons[i].second;
}
sort(dragons.begin(), dragons.end());
for (int i = 0; i < n; i++) {
if (s > dragons[i].first) {
s += dragons[i].second;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
vector<int> strengths(n);
vector<int> bonuses(n);
for (int i = 0; i < n; i++) {
cin >> strengths[i] >> bonuses[i];
}
vector<int> indices(n);
iota(indices.begin(), indices.end(), 0);
sort(indices.begin(), indices.end(), [&](int i, int j) {
return strengths[i] < strengths[j];
});
for (int i = 0; i < n; i++) {
int idx = indices[i];
if (s > strengths[idx]) {
s += bonuses[idx];
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}