-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGOC_G.cpp
More file actions
77 lines (64 loc) · 1.45 KB
/
GOC_G.cpp
File metadata and controls
77 lines (64 loc) · 1.45 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
typedef long long ll;
struct Event {
ll end, start, g;
};
ll fenw[MAXN];
void update(int i, ll val, int n) {
while (i < n) {
if (val > fenw[i]) {
fenw[i] = val;
}
i = (i | (i + 1));
}
}
ll query(int i) {
if (i < 0) return 0;
ll res = 0;
while (i >= 0) {
if (fenw[i] > res) {
res = fenw[i];
}
if (i == 0) break;
i = (i & (i + 1)) - 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<Event> events;
for (int i = 0; i < n; i++) {
ll s, d, g;
cin >> s >> d >> g;
events.push_back({s + d, s, g});
}
sort(events.begin(), events.end(), [](const Event& a, const Event& b) {
return a.end < b.end;
});
vector<ll> ends;
for (int i = 0; i < n; i++) {
ends.push_back(events[i].end);
}
memset(fenw, 0, sizeof(fenw));
ll ans = 0;
for (int i = 0; i < n; i++) {
ll s_i = events[i].start;
ll g_i = events[i].g;
auto it = upper_bound(ends.begin(), ends.begin() + i, s_i);
int idx = it - ends.begin();
ll best = 0;
if (idx > 0) {
best = query(idx - 1);
}
ll dp_i = g_i + best;
ans = max(ans, dp_i);
update(i, dp_i, n);
}
cout << ans << endl;
return 0;
}