Submission #1131527

#TimeUsernameProblemLanguageResultExecution timeMemory
1131527lopkusArt Exhibition (JOI18_art)C++20
100 / 100
118 ms15952 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<int,int>> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin() + 1, a.end()); vector<int> pref(n + 1, 0); vector<int> suf(n + 2, -1e18); for(int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + a[i].second; } for(int i = n; i >= 1; i--) { suf[i] = max(pref[i] - a[i].first, suf[i + 1]); } int ans = 0; for(int i = 1; i < n; i++) { ans = max(ans, suf[i] - pref[i - 1] + a[i].first); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...