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;
pair<long long,long long> arr[500005];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> arr[i].first >> arr[i].second;
}
sort(arr+1,arr+n+1);
long long ans=arr[1].second,ret=arr[1].second;
for(int i=2;i<=n;i++){
ret+=(arr[i].second-arr[i].first+arr[i-1].first);
ans=max(ans,ret);
if(ret<0){
ret=arr[i].second;
}
}
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... |