#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <map>
using namespace std;
int n, k, stree[300000] = {};
vector<pair<int, pair<int, int > > > mines;
vector<long long> gld, svs; vector<pair<long long, int> > nrg;
map<long long, int> cc;
void updh(int i, int s, int e, int l, int u, int d) {
if (s > e || s > u || e < l) {
return;
}
if (s >= l && e <= u) {
stree[i] = max(stree[i], d); return;
}
updh(i*2+1, s, (s+e)/2, l, u, d); updh(i*2+2, (s+e)/2+1, e, l, u, d);
stree[i] = max(stree[i*2+1], stree[i*2+2]);
}
void updv(int i, int d) {
updh(0, 0, n, i, i, d);
}
int maxh(int i, int s, int e, int l, int u) {
if (s > e || s > u || e < l) {
return 0;
}
if (s >= l && e <= u) {
return stree[i];
}
return max(maxh(2*i+1, s, (s+e)/2, l, u), maxh(2*i+2, (s+e)/2+1, e, l, u));
}
int maxv(int l, int u) {
return maxh(0, 0, n, l, u);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n;
for (int i = 0; i < n; i++){
int a, b, c; cin >> a >> b >> c;
mines.push_back(make_pair(a, make_pair(b, c)));
}
int last = 0; gld.push_back(0); nrg.push_back(make_pair(0, 0));
for (int i = 0; i < n; i++){
int x = mines[i].first, cnrg = mines[i].second.second, cgld = mines[i].second.first;
nrg.push_back(make_pair(cnrg+nrg[i].first+last-x, i+1));
svs.push_back(nrg[i].first-x+last); last = x; gld.push_back(gld[i]+cgld);
}
sort(nrg.begin(), nrg.end());
for (int i = 0; i <= n; i++){
cc[nrg[i].first] = i;
}
for (int i = 0; i <= n; i++){
updv(cc[nrg[i].first], nrg[i].second);
}
long long ans = 0;
for (int i = 0; i < n; i++){
ans = max(ans, gld[maxv(cc.lower_bound(svs[i])->second, n)]-gld[i]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
5 ms |
1132 KB |
Output is correct |
24 |
Correct |
6 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
5 ms |
1132 KB |
Output is correct |
24 |
Correct |
6 ms |
1132 KB |
Output is correct |
25 |
Correct |
5 ms |
1004 KB |
Output is correct |
26 |
Correct |
10 ms |
1704 KB |
Output is correct |
27 |
Correct |
11 ms |
1840 KB |
Output is correct |
28 |
Correct |
61 ms |
7264 KB |
Output is correct |
29 |
Correct |
61 ms |
7520 KB |
Output is correct |
30 |
Correct |
130 ms |
15068 KB |
Output is correct |
31 |
Correct |
121 ms |
13916 KB |
Output is correct |
32 |
Correct |
121 ms |
14044 KB |
Output is correct |
33 |
Correct |
122 ms |
13788 KB |
Output is correct |
34 |
Correct |
120 ms |
13660 KB |
Output is correct |
35 |
Correct |
122 ms |
14300 KB |
Output is correct |
36 |
Correct |
124 ms |
14556 KB |
Output is correct |