# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1222497 | mingga | Art Exhibition (JOI18_art) | C++20 | 108 ms | 12112 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 5e5 + 7;
int n, ps[N];
pair<int, int> a[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1);
int mn = 0 - a[1].fi;
int ans = 0;
for(int i = 1; i <= n; i++) {
ps[i] = ps[i - 1] + a[i].se;
ans = max(ans, ps[i] - a[i].fi - mn);
mn = min(mn, ps[i] - a[i + 1].fi);
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... |