#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
class SegmentTree {
private:
long long tree[4 * 2 * N + 7];
int mid (int ss, int se) {
return (ss + se) >> 1;
}
void upd (int ss, int se, int si, int i, long long k) {
if (ss == se) {
tree[si] = max(tree[si], k);
}
else {
if (i <= mid(ss, se)) {
upd (ss, mid(ss, se), si * 2, i, k);
}
else {
upd (mid(ss, se) + 1, se, si * 2 + 1, i, k);
}
tree[si] = max(tree[si * 2], tree[si * 2 + 1]);
}
}
long long qry (int ss, int se, int si, int qs, int qe) {
if (ss > qe || qs > se) {
return 0;
}
if (qs <= ss && se <= qe) {
return tree[si];
}
return max(qry(ss, mid(ss, se), si * 2, qs, qe), qry(mid(ss, se) + 1, se, si * 2 + 1, qs, qe));
}
public:
void update (int i, long long k) {
upd(1, 2 * N, 1, i, k);
}
long long query (int qs, int qe) {
return qry(1, 2 * N, 1, qs, qe);
}
void clear () {
memset(tree, 0, sizeof tree);
}
};
int x[N + 7];
int g[N + 7];
int e[N + 7];
long long pree[N + 7];
long long preg[N + 7];
map<long long, int> newv;
int main () {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d %d %d", &x[i], &g[i], &e[i]);
}
for (int i = 1; i <= n; i++) {
pree[i] = pree[i - 1] + e[i];
preg[i] = preg[i - 1] + g[i];
}
vector<long long> values;
for (int i = 1; i <= n; i++) {
values.push_back(pree[i] - x[i]);
values.push_back(pree[i - 1] - x[i] + 1);
}
sort(values.begin(), values.end());
int currv = 1;
newv[values[0]] = currv;
for (int i = 1; i < values.size(); i++) {
if (values[i] != values[i - 1]) {
currv++;
}
newv[values[i]] = currv;
}
long long ans = 0;
SegmentTree segtree;
segtree.clear();
for (int i = n; i >= 1; i--) {
// cerr << "i: " << i << " " << pree[i] << " " << x[i] << " " << preg[i] << endl;
ans = max(ans, 1LL * g[i]);
segtree.update(newv[pree[i] - x[i]], preg[i]);
// cerr << "x: " << newv[pree[i] - x[i]] << endl;
ans = max(ans, segtree.query(newv[pree[i - 1] - x[i] + 1], 2 * N) - preg[i - 1]);
// cerr << "y: " << newv[pree[i - 1] - x[i] + 1] << endl;
// cerr << "qry: " << segtree.query(newv[pree[i - 1] - x[i] + 1], 2 * N) << endl;
}
cout << ans << endl;
return 0;
}
/*
4
0 5 1
1 7 2
4 4 1
7 15 1
*/
/*
2
0 4 1
3 5 1
*/
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:90:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < values.size(); i++) {
~~^~~~~~~~~~~~~~~
divide.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &x[i], &g[i], &e[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
8 ms |
6648 KB |
Output is correct |
3 |
Correct |
7 ms |
6648 KB |
Output is correct |
4 |
Correct |
7 ms |
6648 KB |
Output is correct |
5 |
Correct |
8 ms |
6648 KB |
Output is correct |
6 |
Correct |
7 ms |
6648 KB |
Output is correct |
7 |
Correct |
8 ms |
6648 KB |
Output is correct |
8 |
Correct |
8 ms |
6648 KB |
Output is correct |
9 |
Correct |
8 ms |
6648 KB |
Output is correct |
10 |
Correct |
8 ms |
6648 KB |
Output is correct |
11 |
Correct |
7 ms |
6648 KB |
Output is correct |
12 |
Correct |
7 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6648 KB |
Output is correct |
2 |
Correct |
8 ms |
6648 KB |
Output is correct |
3 |
Correct |
8 ms |
6776 KB |
Output is correct |
4 |
Correct |
8 ms |
6776 KB |
Output is correct |
5 |
Correct |
8 ms |
6776 KB |
Output is correct |
6 |
Correct |
10 ms |
6904 KB |
Output is correct |
7 |
Correct |
9 ms |
6776 KB |
Output is correct |
8 |
Correct |
9 ms |
6776 KB |
Output is correct |
9 |
Correct |
9 ms |
6904 KB |
Output is correct |
10 |
Correct |
10 ms |
6904 KB |
Output is correct |
11 |
Correct |
14 ms |
7544 KB |
Output is correct |
12 |
Correct |
14 ms |
7544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
7544 KB |
Output is correct |
2 |
Correct |
21 ms |
8308 KB |
Output is correct |
3 |
Correct |
22 ms |
8564 KB |
Output is correct |
4 |
Correct |
97 ms |
16104 KB |
Output is correct |
5 |
Correct |
99 ms |
16364 KB |
Output is correct |
6 |
Correct |
203 ms |
26356 KB |
Output is correct |
7 |
Correct |
189 ms |
25072 KB |
Output is correct |
8 |
Correct |
190 ms |
25224 KB |
Output is correct |
9 |
Correct |
188 ms |
24932 KB |
Output is correct |
10 |
Correct |
187 ms |
24564 KB |
Output is correct |
11 |
Correct |
188 ms |
24936 KB |
Output is correct |
12 |
Correct |
194 ms |
25772 KB |
Output is correct |