# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
465911 | dattranxxx | Art Exhibition (JOI18_art) | C++11 | 260 ms | 24812 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.
/*
* Author : shora
*/
#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cerr << _ << ' ';} cerr << endl;
using namespace std;
using ll = long long;
const ll oo = 1e18;
const int N = 5e5;
struct P {
int v = 0;
ll w = 0, f = 0;
bool operator < (const P& p) {
return w < p.w;
}
};
P a[N+1];
int n;
int main() {
cin.tie(0)->sync_with_stdio(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i].w >> a[i].v;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
a[i].f = a[i-1].f + a[i].v;
ll res = -oo, mx = -oo;
// a[r].f - a[l-1].f - a[r].w + a[l].w
// a[r].f - a[r].w + (a[l].w - a[l-1].f)
for (int r = 1; r <= n; ++r) {
mx = max(mx, a[r].w - a[r-1].f);
res = max(res, a[r].f - a[r].w + mx);
}
cout << res;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |