#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vector<pair<int,int>>a(n+1);
for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
sort(a.begin()+1,a.end());
int ans=0;
int pref[n+1];
pref[0]=0;
for(int i=1;i<=n;i++)pref[i]=pref[i-1]+a[i].second;
int suf[n+2];
for(int i=0;i<=n+1;i++)suf[i]=0;
for(int i=n;i>=1;i--)suf[i]=max(suf[i+1],pref[i]-a[i].first);
for(int i=1;i<=n;i++){
ans=max(ans,suf[i]-pref[i-1]+a[i].first);
//for(int j=i;j<=n;j++)ans=max(ans,pref[j]-pref[i-1]-a[j].first+a[i].first);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |