Submission #1334411

#TimeUsernameProblemLanguageResultExecution timeMemory
1334411ensonArt Exhibition (JOI18_art)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    pair<int, int>A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i].first >> A[i].second;
    }
    sort(A, A+N);
    int B[N] = {A[0].second};
    for(int i = 1; i < N; i++){
        B[i] = A[i].second - A[i].first + A[i-1].first;
    }
    int c = 0, m = 0, j = 0;
    while (j < N-1 && A[j].second - A[j+1].first + A[j].first < 0){
        j++;
    }
    for(int i = j; i < N; i++){
        c += B[i];
        if (c < 0) c = A[i].second;
        m = max(c, m);
    }
    cout << m;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...