제출 #234296

#제출 시각아이디문제언어결과실행 시간메모리
234296Toirov_SadiArt Exhibition (JOI18_art)C++17
100 / 100
804 ms24272 KiB
#include<bits/stdc++.h>

using namespace std;

int n;
vector<long long> p;
vector<pair<long long, int>> a;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++){
        int y;
        long long x;
        cin >> x >> y;
        a.push_back({x, y});
    }
    sort(a.begin(), a.end());

    p.resize(n, 0ll);
    for(int i = 0; i < n; i ++){
        if(i > 0) p[i] = p[i - 1];
        p[i] += a[i].second;
    }

    int j = 0;
    long long mx = 0;
    long long mn = LONG_MAX;

    for(int i = 0; i < n; i ++){
        long long x = (i == 0 ? 0 : p[i - 1]) - a[i].first;
        if(x < mn){
            mn = x;
            j = i;
        }

        long long sum = p[i];
        if(j > 0) sum -= p[j - 1];
        mx = max(mx, sum - (a[i].first - a[j].first));
    }

    cout << mx << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...