#include<bits/stdc++.h>
using namespace std;
const int maxn = 100009;
int n;
long long e[maxn], E[maxn];
long long g[maxn], G[maxn];
long long x[maxn], X[maxn];
long long c[maxn], f[maxn];
void upd(long long x, long long d){
while(x <= n+1){
f[x] = min(f[x], d);
x += (x & -x);
}
}
long long cnt(long long x){
long long ans = 1e18;
while(x){
ans = min(ans, f[x]);
x -= (x & -x);
}
return ans;
}
main(){
cin >> n;
for(long long i = 1; i <= n; i++){
cin >> x[i] >> g[i] >> e[i];
X[i] = x[i] ;
G[i] = g[i] + G[i - 1];
E[i] = e[i] + E[i - 1];
}
//c[r] > c[l], r > l; g[r] - g[l]
vector<pair<long long,long long> > v;
for(long long i = 0; i <= n; i++){
v.push_back({E[i] - X[i], i});
}
sort(v.begin(), v.end());
for(long long i = 0; i < v.size(); i++)
c[v[i].second] = i + 1;
for(long long i = 1; i <= n+1; i++)
f[i] = 1e18;
long long ans = 0;
for(long long i = 0; i <= n; i++){
long long T = cnt(c[i] - 1);
ans = max(ans, G[i] - T);
ans = max(ans, g[i]);
upd(c[i], G[i]);
}
cout << ans << endl;
}
Compilation message
divide.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
divide.cpp: In function 'int main()':
divide.cpp:37:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < v.size(); i++)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1020 KB |
Output is correct |
2 |
Correct |
10 ms |
1404 KB |
Output is correct |
3 |
Correct |
12 ms |
1524 KB |
Output is correct |
4 |
Correct |
54 ms |
5484 KB |
Output is correct |
5 |
Correct |
63 ms |
5800 KB |
Output is correct |
6 |
Correct |
132 ms |
11332 KB |
Output is correct |
7 |
Correct |
100 ms |
10180 KB |
Output is correct |
8 |
Correct |
100 ms |
10252 KB |
Output is correct |
9 |
Correct |
95 ms |
10056 KB |
Output is correct |
10 |
Incorrect |
94 ms |
10056 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |