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;
//#include<bits/extc++.h>
//__gnu_pbds
int n;
vector<pair<ll,ll> > arr;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
arr.resize(n);
for(int i=0;i<n;i++){
cin>>arr[i].first>>arr[i].second;
}
sort(arr.begin(),arr.end());
ll maxn[n] = {0};
maxn[0] = arr[0].first+arr[0].second;
ll ans = 0;
for(int i=1;i<n;i++){
ans = max(ans,maxn[i-1]+arr[i].second-arr[i].first) ;
maxn[i] = max(maxn[i-1]+arr[i].second,arr[i].second+arr[i].first);
}
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... |