#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pon ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int T=1;
#define ponchik signed main
#define pb push_back
#define pf push_front
#define endl "\n"
#define F first
#define S second
const int N=1e5+69,INF=1e18+1488;
int cnt[N];
map<pair<int,int>,int>mp;
void solve() {
int n;
vector <pair<int,int>> v;
cin>>n;
for (int i=0; i<n; i++)
{
int a,b;
cin>>a>>b;
v.pb({a,b});
}
sort(v.begin(),v.end());
int sum=v[0].S,ans=0,pos1=0;
for (int i=1; i<n; i++)
{
sum+=v[i].S;
if (v[i].F-v[pos1].F<=sum) ans+=sum,sum=0,pos1=i;
}
int pos2=0;
sum=0;
for (int i=1; i<=pos1; i++)
{
sum+=v[i-1].S;
if (v[i].F-v[pos2].F>=sum) ans-=sum,sum=0,pos2=i;
}
cout<<max(ans-v[pos1].F+v[pos2].F,v[0].S);
}
ponchik (/*Alfar ABI*/ ) {
pon
// freopen( "###.in" ,"r",stdin); freopen( "###.out" ,"w",stdout);
// cin>>T;
while (T--){solve();}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |