-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1203F1.cpp
More file actions
45 lines (41 loc) · 1.08 KB
/
1203F1.cpp
File metadata and controls
45 lines (41 loc) · 1.08 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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r; cin >> n >> r;
vector<pair<int, int>> pos;
multimap<int, int> neg;
for(int i = 0, a = 0, b = 0; i < n; i++) {
cin >> a >> b;
if(b <= 0) neg.insert({a, b});
else pos.push_back({a, b});
}
sort(pos.begin(), pos.end());
bool ok = true;
for(int i = 0; i < pos.size(); i++) {
if(r < pos[i].first) {
ok = false;
break;
}
r += pos[i].second;
}
while(neg.size()) {
int cur = neg.rbegin()->first, t = neg.rbegin()->second;
auto pos = neg.upper_bound(r + t);
if(pos == neg.end()) {
r += t;
pos--;
neg.erase(pos);
}
else {
while(r >= cur && pos != neg.end()) {
r += pos->second;
pos = neg.erase(pos);
}
if(pos != neg.end()) {
ok = false;
break;
}
}
}
cout << (ok ? "YES" : "NO") << endl;
}