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<int64_t,int64_t>>arr(n);
for (int i =0;i<n;++i){
cin>>arr[i].first>>arr[i].second;
}
sort(arr.begin(),arr.end(),[&](pair<int64_t,int64_t>a,pair<int64_t,int64_t>b){
return a.first<b.first;
});
int64_t ans=0;
int64_t cur =0;
int64_t maxxy=0;
for (int i =0;i<n;++i){
ans =max(cur+arr[i].second - arr[i].first,ans);
ans=max(ans,arr[i].second);
cur = max(cur + arr[i].second ,arr[i].second+arr[i].first);
}
cout<<ans<<endl;
return 0;}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:17:9: warning: unused variable 'maxxy' [-Wunused-variable]
17 | int64_t maxxy=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... |