#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] = 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]);
ans = max(ans, segtree.query(newv[pree[i - 1] - x[i - 1]], 2 * N) - preg[i - 1]);
segtree.update(newv[pree[i] - x[i]], preg[i]);
}
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]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6652 KB |
Output is correct |
2 |
Incorrect |
7 ms |
6648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6648 KB |
Output is correct |
2 |
Correct |
8 ms |
6648 KB |
Output is correct |
3 |
Incorrect |
8 ms |
6648 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
7160 KB |
Output is correct |
2 |
Correct |
19 ms |
7796 KB |
Output is correct |
3 |
Correct |
20 ms |
7800 KB |
Output is correct |
4 |
Correct |
82 ms |
12848 KB |
Output is correct |
5 |
Correct |
86 ms |
13164 KB |
Output is correct |
6 |
Correct |
174 ms |
20100 KB |
Output is correct |
7 |
Correct |
159 ms |
18848 KB |
Output is correct |
8 |
Correct |
166 ms |
19016 KB |
Output is correct |
9 |
Correct |
159 ms |
18916 KB |
Output is correct |
10 |
Incorrect |
161 ms |
18700 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |