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 <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define a first
#define b second
#define endl "\n"
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n;
cin>>n;
vector<pair<llo,llo>> aa;
llo bb,cc;
for(llo i=0;i<n;i++){
cin>>bb>>cc;
aa.pb(mp(bb,cc));
}
sort(aa.begin(),aa.end());
llo ma=aa[n-1].b;
llo mi=aa[n-1].b-aa[n-1].a;
for(llo i=n-2;i>=0;i--){
ma=max(ma,aa[i].b);
llo co=aa[i].b+mi+aa[i].a;
ma=max(ma,co);
mi=max(mi+aa[i].b,aa[i].b-aa[i].a);
}
cout<<ma<<endl;
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... |