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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17;
int a[100005],b[100005],c[100005],g[100000],pr[100005],d[400005];
void update(int v,int l,int r,int pos,int x){
if(l==r){
d[v]=x;
return;
}
int m=(l+r)>>1;
if(pos<=m){
update((v<<1),l,m,pos,x);
}
else{
update((v<<1)+1,m+1,r,pos,x);
}
d[v]=max(d[v<<1],d[(v<<1)+1]);
}
int fun(int v,int l,int r,int x){
if(l==r){
return l;
}
int m=(l+r)>>1;
if(d[(v<<1)+1]>=x)return fun((v<<1)+1,m+1,r,x);
return fun((v<<1),l,m,x);
}
main(){
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i] >> c[i];
pr[i]+=pr[i-1]+c[i];
g[i]+=g[i-1]+b[i];
update(1,1,n,i,pr[i]-a[i]);
}
int ans=0;
for(int i=1;i<=n;i++){
int j=fun(1,1,n,pr[i-1]-a[i]);
ans=max(ans,g[j]-g[i-1]);
}
cout << ans;
}
Compilation message (stderr)
divide.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |