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>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
const int MX=500010;
int n;
pli P[MX];
ll S[MX], A[MX], ans;
inline ll get(int x){ return S[x]-A[x]; }
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>P[i].first>>P[i].second;
sort(P+1, P+n+1);
for(int i=1; i<=n; i++) A[i]=P[i].first;
for(int i=1; i<=n; i++) S[i]=S[i-1]+P[i].second;
vector<int> V;
for(int i=n; i>=1; i--)
if(V.empty() || get(V.back())<get(i)) V.push_back(i);
reverse(V.begin(), V.end());
for(int i=1, p=0; i<=n; i++){
while(p+1<(int)V.size() && V[p]<i) p++;
ans=max(ans, get(V[p])-S[i-1]+A[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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |