제출 #1175489

#제출 시각아이디문제언어결과실행 시간메모리
1175489banganArt Exhibition (JOI18_art)C++20
100 / 100
119 ms10232 KiB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<i64> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
    }

    std::vector<int> idx(n);
    std::iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&](int i, int j) {
        return a[i] < a[j];
    });

    i64 max = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        max = std::max(max + b[idx[i]], b[idx[i]]);
        ans = std::max(ans, max);
        
        if (i + 1 < n) {
            max -= a[idx[i + 1]] - a[idx[i]];
        }
    }
    std::cout << ans;

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