이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;
vector<ll>x(200001),d(200001);
vector<ll>g(200001);
vector<ll>t(800001,1e18+1);
void update(int v,int l,int r,int val,int pos){
if(l==r){
t[v]=val;
return;
}
int m=(l+r)/2;
if(pos<=m)update(2*v,l,m,val,pos);
if(pos>m)update(2*v+1,m+1,r,val,pos);
t[v]=min(t[2*v],t[2*v+1]);
}
int get(int v,int l,int r,ll val){
if(l==r){
return l;
}
int m=(l+r)/2;
if(t[2*v]<=val)return get(2*v,l,m,val);
if(t[2*v+1]<=val)return get(2*v+1,m+1,r,val);
return -1;
}
void solve(){
int n;cin>>n;
vector<ll>pref(n+1);
pref[0]=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>g[i]>>d[i];
d[i]+=d[i-1];
pref[i]=pref[i-1]+g[i];
}
ll mx=0;
for(int i=1;i<=n;i++){
update(1,1,n,d[i-1]-x[i],i);
int ind=get(1,1,n,d[i]-x[i]);
mx=max(mx,pref[i]-pref[ind-1]);
}
cout<<mx;
}
int main(){
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |