Submission #577881

#TimeUsernameProblemLanguageResultExecution timeMemory
577881Trisanu_DasArt Exhibition (JOI18_art)C++17
100 / 100
570 ms28620 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<array<long, 2>> v(n); for (auto &[a, b] : v) cin >> a >> b; sort(v.begin(), v.end()); vector<long> pref(n + 1, 0); for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + v[i][1]; vector diff(pref.begin() + 1, pref.end()); for (int i = 0; i < n; i++) diff[i] -= v[i][0]; long res = 0; long cur = LONG_MIN / 2; for (int i = n - 1; i >= 0; i--) { cur = max(cur, diff[i]); res = max(res, cur + v[i][0] - pref[i]); } cout << res << '\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...