Submission #1111952

# Submission time Handle Problem Language Result Execution time Memory
1111952 2024-11-13T12:41:46 Z vjudge1 Art Exhibition (JOI18_art) C++11
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair <ll,ll>
#define f first 
#define s second 
const int N=5e5+5;
const ll INF=1e15+5;

int n;
ll ans=0,mx=0,mn=INF,sum=0,pos,tmp;
pll p[N]; // size , value
bool ok=1;

bool cmp(pll x,pll 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++) cout << p[i].f << " " << p[i].s << "\n";
    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;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:32:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |         auto [a,b]=p[i];
      |              ^
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -