# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926613 | 2024-02-13T12:35:36 Z | VMaksimoski008 | Art Exhibition (JOI18_art) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<pair<ll, ll> > v(n+1); for(int i=1; i<=n; i++) cin >> v[i].first >> v[i].second; sort(v.begin()+1, v.end()); ll ans = 0, mx = -1e18, S = 0; for(int i=1; i<=n; i++) { mx = max(mx, v[i].first - S); S += v[i].second ans = max(ans, S - v[i].first + mx); } cout << ans << '\n'; return 0; }