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>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e5+5;
const ll C=1e9+10;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((ll)(i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,d[N],g[N],x[N],ans,ansid;
struct node{
ll val;
node *lc,*rc;
}*rt=new node{INF,0,0};
ll get(node *nd){
if(nd)return nd->val;
return INF;
}
void ins(node *nd,ll l,ll r,ll to,ll D){
if(l==r-1){nd->val=min(nd->val,D);return ;}
ll mid=(l+r)>>1;
if(to<mid){
if(!nd->lc)nd->lc=new node{INF,0,0};
ins(nd->lc,l,mid,to,D);
}else{
if(!nd->rc)nd->rc=new node{INF,0,0};
ins(nd->rc,mid,r,to,D);
}
nd->val=min(get(nd->lc),get(nd->rc));
}
ll q(node *nd,ll l,ll r,ll ql,ll qr){
if(l>=ql&&r<=qr)return nd->val;
if(l>=qr||r<=ql)return INF;
ll mid=(l+r)>>1;
if(!nd->lc)nd->lc=new node{INF,0,0};
if(!nd->rc)nd->rc=new node{INF,0,0};
return min(q(nd->lc,l,mid,ql,qr),q(nd->rc,mid,r,ql,qr));
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
REP1(i,n){
cin>>x[i]>>g[i]>>d[i];
g[i]+=g[i-1];d[i]+=d[i-1];
}
ins(rt,0,2*C,d[0]-x[1]+C,0);
REP1(i,n){
ansid=q(rt,0,2*C,0,d[i]-x[i]+1+C);
if(ansid!=INF)ans=max(ans,g[i]-g[ansid]);
ins(rt,0,2*C,d[i]-x[i+1]+C,i);
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |