Submission #880407

#TimeUsernameProblemLanguageResultExecution timeMemory
880407frostray8653Art Exhibition (JOI18_art)C++17
100 / 100
159 ms20060 KiB
#include <bits/stdc++.h> #define int long long #define IO ios::sync_with_stdio(0), cin.tie(0) #define FOR(i, a, b) for (int i = a; i <= b; i++) using namespace std; using pii = pair<int, int>; void dbg() {;} template<class T, class ...U> void dbg(T a, U ...b) { cout << a << " "; dbg(b...); } void ent() { cout << "\n"; } const int INF = 1e17; const int N = 500005; pii a[N]; int pre[N]; int bef[N], bck[N]; signed main() { IO; int n; cin >> n; FOR(i, 1, n) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1, [&](pii p, pii q) { return p.first < q.first; }); FOR(i, 1, n) pre[i] = pre[i - 1] + a[i].second; bef[0] = -INF; for (int i = 1; i <= n; i++) { bef[i] = a[i].first - pre[i - 1]; bef[i] = max(bef[i], bef[i - 1]); } bck[n + 1] = -INF; for (int i = n; i >= 1; i--) { bck[i] = pre[i] - a[i].first; bck[i] = max(bck[i], bck[i + 1]); } int ans = -INF; for (int i = 1; i <= n; i++) ans = max(ans, bef[i] + bck[i]); 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...