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;
#define ll long long
#define ft first
#define sd second
const ll MOD = 1e9+7;
ll n, ans, pr[200005], p[200005], d[200005], g[200005];
void fun(){
cin>>n;
for(ll i = 1, a, b, c, l = 0; i <= n; i++){
cin>>a>>b>>c;
if(i == 1)l = a;
pr[i] = pr[i - 1] + c - (a - l);
p[i] = c;
d[i] = (a - l);
g[i] = b + g[i - 1];
l = a;
}
for(ll i = n - 1; i; i--)pr[i] = max(pr[i], pr[i + 1]);
for(ll i = 1, sum = 0; i <= n; i++){
ll l = i, r = n, res = 0;
while(r >= l){
ll m = (l + r) / 2;
if(pr[m] - sum >= 0)
l = m + 1, res = m;
else
r = m - 1;
}
ans = max(ans, g[res] - g[i - 1]);
sum += p[i] - d[i + 1];
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int ttt = 1;
//cin>>ttt;
while(ttt--)fun();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |