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>
#define ll long long
#define le node+node
#define ri node+node+1
#define mid (l+r)/2
using namespace std;
const ll inf = 2e5+9,MX = 1e18+9;
ll n,ans,x[inf],g[inf],e[inf];
ll cnt;
map<ll,ll> compress;
ll tree[inf<<2];
void build(ll node,ll l,ll r){
if(l == r)
return void(tree[node] = MX);
build(le,l,mid);
build(ri,mid+1,r);
tree[node] = min(tree[le],tree[ri]);
}
void update(ll node,ll l,ll r,ll idx,ll val){
if(l == r)
return void(tree[node] = min(tree[node],val));
if(idx <= mid)
update(le,l,mid,idx,val);
else
update(ri,mid+1,r,idx,val);
tree[node] = min(tree[le],tree[ri]);
}
ll query(ll node,ll l,ll r,ll x,ll y){
if(l>r || r<x || l>y || x>y)
return MX;
if(l>=x && r<=y)
return tree[node];
return min(query(le,l,mid,x,y),query(ri,mid+1,r,x,y));
}
signed main(){
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
scanf("%lld%lld%lld",x+i,g+i,e+i),g[i] += g[i-1],
e[i] += e[i-1],compress[e[i]-x[i]],compress[e[i-1]-x[i]];
for(auto &o:compress)
o.second = ++cnt;
build(1,1,cnt);
for(ll i=1;i<=n;i++){
update(1,1,cnt,compress[ e[i-1]-x[i] ],g[i-1]);
ans = max(ans,g[i]-query(1,1,cnt,1,compress[ e[i]-x[i] ]));
}
printf("%lld\n",ans);
}
Compilation message (stderr)
divide.cpp: In function 'int main()':
divide.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
divide.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%lld%lld%lld",x+i,g+i,e+i),g[i] += g[i-1],
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |