#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;
}
// cout<<pos1<<endl<<ans1;
int pos2=0;
sum=0;
for (int i=1; i<=pos1+1; i++)
{
sum+=v[i-1].S;
if (v[i].F-v[pos2].F>=sum) ans-=sum,sum=0,pos2=i;
}
cout<<ans-v[pos1].F+v[pos2].F;
// cout<<pos2<<" "<<pos1<<endl<<ans-v[pos1].F+v[pos2].F;
}
ponchik (/*Alfar ABI*/ ) {
pon
// freopen( "###.in" ,"r",stdin); freopen( "###.out" ,"w",stdout);
// cin>>T;
while (T--){solve();}
}
# |
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 |
- |