#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
signed main()
{
int n,sum=0;
cin>>n;
pair<int,int>niz[n];
for(int i=0;i<n;i++){
cin>>niz[i].f;
cin>>niz[i].s;
sum+=niz[i].s;
}
sort(niz,niz+n);
sum-=(niz[n-1].f-niz[0].f);
int l=0,r=n-1;
int maxsum=sum;
while(l<r){
int sl=0,sr=0;
while(l<r&&niz[l].f==niz[l+1].f){
sl+=niz[l].s;
l++;
}
sl+=niz[l].s;
while(r>l&&niz[r].f==niz[r-1].f){
sr+=niz[r].s;
r--;
}
sr+=niz[r].s;
int promenaL=(niz[l+1].f-niz[l].f)-sl;
int promenaR=(niz[r].f-niz[r-1].f)-sr;
if(promenaL>promenaR){
sum+=promenaL;
l++;
}
else{
sum+=promenaR;
r--;
}
maxsum=max(maxsum,sum);
}
cout<<maxsum<<endl;
return 0;
}
# |
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 |
- |