#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair <int,int>
#define f first
#define s second
const int N=5e5+5;
const int INF=1e16;
int n,ans=0,mx=0,mn=INF,sum=0,pos,tmp;
pii arr[N]; // size , value
vector <pii> v;
bool cmp(pii x,pii y){
if(abs(pos-x.f)!=abs(pos-y.f)) return abs(pos-x.f)<abs(pos-y.f);
else return x.s>y.s;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++){
cin >> arr[i].f >> arr[i].s;
if(arr[i].s>tmp){
tmp=arr[i].s;
v.clear();
v.push_back({arr[i].f,arr[i].s});
}
else if(arr[i].s==tmp) v.push_back({arr[i].f,arr[i].s});
}
for(auto [x,y]:v){
pos=x;
sum=0,mx=0,mn=INF;
sort(arr+1,arr+1+n,cmp);
for(int i=1;i<=n;i++){
auto [a,b]=arr[i];
mx=max(mx,a);
mn=min(mn,a);
sum+=b;
ans=max(ans,sum-(mx-mn));
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |