This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 5, msz = (1 << 17);
int n, X[mx]; long long G[mx], E[mx], seg[msz * 2], ans;
void upd(int i, long long v){
seg[i += msz] = v;
for (i /= 2; i; i /= 2) seg[i] = min(seg[i * 2], seg[i * 2 + 1]);
}
int qry(long long v){
int i = 1;
while (i < msz) i = (seg[i * 2] <= v) ? i * 2 : i * 2 + 1;
return i - msz;
}
int main(){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> X[i] >> G[i] >> E[i];
G[i] += G[i - 1]; E[i] += E[i - 1];
}
memset(seg, 0x3f, sizeof(seg));
for (int i = 1; i <= n; i++){
upd(i, E[i - 1] - X[i]);
int pos = qry(E[i] - X[i]);
ans = max(ans, G[i] - G[pos - 1]);
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |