Submission #1323986

#TimeUsernameProblemLanguageResultExecution timeMemory
1323986sh_qaxxorov_571Art Exhibition (JOI18_art)C++20
100 / 100
130 ms8256 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Artwork {
    long long a, b;
};
bool compareArt(const Artwork& x, const Artwork& y) {
    return x.a < y.a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<Artwork> arts(n);
    for (int i = 0; i < n; i++) {
        cin >> arts[i].a >> arts[i].b;
    }
    sort(arts.begin(), arts.end(), compareArt);
    long long max_ans = -2e18; 
    long long current_sum = 0;
    long long prev_min_val = 0; 
    long long temp_max = -2e18;
    for (int i = 0; i < n; i++) {
        current_sum += arts[i].b;
        
        if (i == 0) {
            temp_max = arts[i].b;
        } else {
            temp_max = max(arts[i].b, temp_max + arts[i].b - (arts[i].a - arts[i-1].a));
        }
        max_ans = max(max_ans, temp_max);
    }
    cout << max_ans << endl;

    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...