이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005,INF=1e9;
long long prefg[MAXN],prefd[MAXN];
int x[MAXN],bit[2*MAXN],MAX;
map<long long,int> mp;
int query(int now){
int ret=INF;
for(int i=now;i>0;i-=(i&(-i)))ret=min(ret,bit[i]);
return ret;
}
void update(int now,int val){
for(int i=now;i<=MAX;i+=(i&(-i)))bit[i]=min(bit[i],val);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
for(int i=0;i<2*MAXN;i++)bit[i]=INF;
int n,g,d;
cin >> n;
for(int i=1;i<=n;i++){
cin >> x[i];
cin >> g >> d;
prefg[i]=prefg[i-1]+g;
prefd[i]=prefd[i-1]+d;
}
for(int i=0;i<=n;i++){
mp[prefd[i]-x[i+1]];
if(i)mp[prefd[i]-x[i]];
}
for(map<long long,int>::iterator it=mp.begin();it!=mp.end();++it){
MAX++;
mp[it->first]=MAX;
}
long long ans=0;
update(mp[prefd[0]-x[1]],1);
for(int i=1;i<=n;i++){
int idx=query(mp[prefd[i]-x[i]]);
if(idx!=INF){
ans=max(ans,prefg[i]-prefg[idx-1]);
}
update(mp[prefd[i]-x[i+1]],i+1);
}
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... |