#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define int long long
#define ss second
#define ff first
#define endl '\n'
typedef pair<int,int> pp;
signed main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<pair<int,int> > v(n+1);
for(int i=1; i<=n; i++){
int a,b; cin>>a>>b;
v[i]={a,b};
}
vector<int> pref(n+1);
sort(v.begin(),v.end());
for(int i=1; i<=n; i++){
pref[i]=pref[i-1]+v[i].ss;
}
int sv=1e18;
int ans=0,f=0,s=1e18;
for(int i=1; i<=n; i++){
if(pref[i]-v[i].ff>=f){
f=max(f,pref[i]-v[i].ff);
s=min(s,min(sv,pref[i-1]-v[i].ff));
}else{
sv=min(sv,pref[i-1]-v[i].ff);
}
ans=max(ans,f-s);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |