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;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<pair<long long, long long> > v;
long long a, b, p[n], tmp[n], curr=0, ans=0;
for(int i=0; i<n; i++){
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
tmp[0]=p[0]=v[1].first-v[0].first-v[0].second;
for(int i=1; i<n-1; i++){
p[i]=p[i-1]+v[i+1].first-v[i].first-v[i].second;
tmp[i]=max(tmp[i-1], p[i]);
}
curr=v[0].second;
//cout << curr << endl;
for(int i=0; i<n; i++){
if(i>0) curr+=(v[i].second-v[i].first+v[i-1].first);
//cout << i << " " << curr << endl;
ans=max(ans, curr);
if(i>0) ans=max(ans, curr+tmp[i-1]);
}
cout << ans;
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... |