Submission #1289749

#TimeUsernameProblemLanguageResultExecution timeMemory
1289749hahaArt Exhibition (JOI18_art)C++20
100 / 100
132 ms12104 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 5e5 + 5; int n; pair<ll, ll> a[maxn]; ll prefix[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + a[i].second; ll ans = LLONG_MIN; ll best = prefix[0] - a[1].first; for (int r = 1; r <= n; r++) { ans = max(ans, prefix[r] - a[r].first - best); best = min(best, prefix[r] - a[r + 1].first); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...