제출 #453762

#제출 시각아이디문제언어결과실행 시간메모리
453762ponytailArt Exhibition (JOI18_art)C++17
100 / 100
854 ms33016 KiB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
signed main(){
    int N; cin >> N;
    pair<ll, ll> A[N+1];
    priority_queue<pair<ll, int> > pq;
    for(int i=1; i<=N; i++){
        cin >> A[i].first >> A[i].second;
    }
    sort(A+1, A+N+1);
    ll ps[N+1];
    ps[0] = 0;
    for(int i=1; i<=N; i++){
        ps[i] = ps[i-1] + A[i].second;
    }
    ll S = 0;
    for(int i=2; i<=N; i++){
        S = S + A[i].second - A[i].first + A[i-1].first;
        pq.push({S, i});
    }
    ll ans = 0;
    for(int i=1; i<=N; i++){
        ans = max(ans, A[i].second);
    }
    for(int i=1; i<=N; i++){
        while(pq.top().second<i) pq.pop();
        if(pq.size()) ans = max(ans, ps[pq.top().second] - ps[i-1] - A[pq.top().second].first + A[i].first);
    }
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...