Submission #548840

#TimeUsernameProblemLanguageResultExecution timeMemory
548840KiprasArt Exhibition (JOI18_art)C++17
50 / 100
1093 ms20300 KiB
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll maxN = 5e5+10;

pair<ll, ll> a[maxN];

ll maxVal=0;

void check(ll mn, ll mx, ll s){
    maxVal=max(maxVal, s-abs(mn-mx));
}

int main()
{

    ios_base::sync_with_stdio();cin.tie(nullptr);

    ll n;

    cin>>n;
    for(int i = 0; i < n; i++){
        ll aa, bb;
        cin>>aa>>bb;
        a[i]={aa, bb};
    }

    sort(a, a+n);



    for(int i = 0; i < n; i++){
        ll mnS=a[i].first;
        ll mxS=a[i].first;
        ll s = a[i].second;
        check(mnS, mxS, s);
        for(int x = i+1; x < n; x++){
            s+=a[x].second;
            mnS=min(mnS, a[x].first);
            mxS=max(mxS, a[x].first);
            check(mnS, mxS, s);
        }
    }

    cout<<maxVal;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...