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 <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin>>n;
vector<pair<long long, long long>> vect(n);
for (long long i=0;i<n;i++) cin>>vect[i].first>>vect[i].second;
sort(vect.begin(), vect.end());
vector<long long> adds(n);
adds[n-1]=vect[n-1].second;
for (long long i=0;i<n-1;i++){
adds[i]=vect[i].second-vect[i+1].first+vect[i].first;
}
long long current=0, best=-1e15-1;
for (long long i=n-1;i>=0;i--){
current+=adds[i];
current=max(current, vect[i].second);
best=max(best, current);
}
cout<<best<<'\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... |