Submission #1275526

#TimeUsernameProblemLanguageResultExecution timeMemory
1275526MisterReaperArt Exhibition (JOI18_art)C++20
100 / 100
124 ms8260 KiB
// File artexhibition.cpp created on 02.10.2025 at 19:25:28
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

constexpr i64 inf = i64(1E18);

template<typename T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    std::cin >> N;

    std::vector<std::array<i64, 2>> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i][0] >> A[i][1];
    }

    std::sort(A.begin(), A.end());

    i64 ans = 0, x = -inf, sum = 0;
    for (int i = 0; i < N; ++i) {
        chmax(x, -sum + A[i][0]);
        sum += A[i][1];
        chmax(ans, sum + x - A[i][0]);
    }

    std::cout << ans << '\n';

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