#include<bits/stdc++.h>
using namespace std;
pair<long long int,long long int>a[(int)5e5+5];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
sort(a,a+n);
long long int pre=0,mn=0,sum=0,ans=0;
for(int i=0;i<n;i++){
sum+=a[i].second-a[i].first+(i?a[i-1].first:0);
pre=(i?a[i-1].second:0)-a[i].first+(i?a[i-1].first:0);
mn=min(mn,pre);
ans=max(ans,sum-mn);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |