Submission #64047

#TimeUsernameProblemLanguageResultExecution timeMemory
64047patrikpavic2Art Exhibition (JOI18_art)C++17
100 / 100
782 ms246636 KiB
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair < ll , ll > pii;

const int N = 5e5 + 500;

vector < pii > v;
set < pii > s;
ll sol = 0, pref[N];
int n;

int main(){
    scanf("%d", &n);
    for(int i = 0;i<n;i++){
        ll x, y;scanf("%lld%lld", &x, &y);
        v.push_back({x, y});
    }
    sort(v.rbegin(), v.rend());
    for(int i = 0;i<n;i++){
        pref[i] = (i ? pref[i - 1] : 0) + v[i].Y;
    }
    for(int i = 0;i<n;i++){
        s.insert({pref[i] + v[i].X, i});
    }
    for(int i = 0;i<n;i++){
        sol = max(sol, (s.rbegin()->X) - (i ? pref[i - 1] : 0) - v[i].X);
        s.erase({pref[i] + v[i].X, i});
    }
    printf("%lld\n", sol);
    return 0;
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
art.cpp:24:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         ll x, y;scanf("%lld%lld", &x, &y);
                 ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...