# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1228999 | adad | Art Exhibition (JOI18_art) | C++20 | 108 ms | 12112 KiB |
#include <bits/stdc++.h>
#define TASK ""
#define MASK(i) (1<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define int long long
#define fi first
#define se second
using namespace std;
const long long INF = 1e17, MOD = 1e9 + 7, maxN = 5e5 + 5;
int n, p[maxN];
pair<int, int> x[maxN];
signed main() {
if (fopen(TASK ".INP", "r")) {
freopen(TASK ".INP", "r", stdin);
freopen(TASK ".OUT", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i ++) cin >> x[i].fi >> x[i].se;
sort(x + 1, x + n + 1);
p[1] = x[1].se;
for(int i = 2; i <= n; i ++) p[i] = p[i - 1] + x[i].se;
int maa = -INF, res = -INF;
// p[r] - p[l - 1] - x[r].fi + x[l].fi
// (p[r] - x[r].fi) + (x[l].fi - p[l - 1])
for(int i = 1; i <= n; i ++) {
maa = max(maa, x[i].fi - p[i - 1]);
res = max(res, maa + p[i] - x[i].fi);
}
cout << res;
}
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... |