이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define MAXN 500007
using namespace std;
const long long inf=1e18;
struct pic{
long long sz,cost;
};
int n;
pic c[MAXN];
long long ans;
bool cmp(pic fr,pic sc){
return fr.sz<sc.sz;
}
void solve(int l,int r){
if(l>r)return;
if(l==r){
ans=max(ans,c[l].cost);
return;
}
int mid=(l+r)/2;
long long maxpref=0,maxsuff=0,sum;
sum=0;
for(int i=mid;i>=l;i--){
sum+=c[i].cost;
maxpref=max(maxpref,sum-(c[mid].sz-c[i].sz));
}
sum=0;
for(int i=mid+1;i<=r;i++){
sum+=c[i].cost;
maxsuff=max(maxsuff,sum-(c[i].sz-c[mid+1].sz));
}
ans=max(ans,maxpref+maxsuff-(c[mid+1].sz-c[mid].sz));
solve(l,mid);
solve(mid+1,r);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>c[i].sz>>c[i].cost;
}
sort(c+1,c+n+1,cmp);
solve(1,n);
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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |