답안 #1111953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111953 2024-11-13T12:43:45 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 336 KB
#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 p[N]; // size , value

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 >> p[i].f >> p[i].s;
        if(p[i].s>tmp) tmp=p[i].s,pos=p[i].f;
    }
    sort(p+1,p+1+n,cmp);
    for(int i=1;i<=n;i++){
        auto [a,b]=p[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 -