Submission #379230

#TimeUsernameProblemLanguageResultExecution timeMemory
379230penguinhackerArt Exhibition (JOI18_art)C++14
100 / 100
255 ms28908 KiB
// source: https://oj.uz/problem/view/JOI18_art #include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN = 500000; int n; ll pre[mxN], suf[mxN]; pair<ll, ll> a[mxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second; sort(a, a + n); for (int i = 1; i < n; ++i) pre[i] = suf[i] = pre[i - 1] + a[i].second - (a[i].first - a[i - 1].first); for (int i = n - 2; ~i; --i) suf[i] = max(suf[i], suf[i + 1]); ll ans = 0; for (int i = 0; i < n; ++i) ans = max(ans, suf[i] - pre[i] + a[i].second); 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...