# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577875 | Trisanu_Das | Art Exhibition (JOI18_art) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<pair<int, int>> a(n);
for (auto p : v) cin >> p.first >> p.second;
sort(a.begin(), a.end());
int pref[n + 1]
for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + v[i][1];
vector diff(pref + 1, pref + n + 1);
for (int i = 0; i < n; i++) diff[i] -= v[i][0];
long ans = 0, tmp = INT_MIN / 2;
for (int i = n - 1; i > -1; i--)
{
tmp = max(tmp, diff[i]); ans = max(ans, tmp + v[i][0] - pref[i]);
}
cout << ans << '\n';
}