# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
285474 | BeanZ | Art Exhibition (JOI18_art) | C++14 | 233 ms | 28904 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;
#define ll long long
#define endl '\n'
const int N = 4e6 + 20;
const int mod = 998244353;
pair<ll, ll> a[500005];
ll sum[500005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("VietCT.INP", "r")){
freopen("VietCT.INP", "r", stdin);
freopen("VietCT.OUT", "w", stdout);
}
ll n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
priority_queue<ll, vector<ll>, greater<ll>> pq;
ll ans = 0;
for (int i = 1; i <= n; i++){
sum[i] = sum[i - 1] + a[i].second;
if (pq.size()){
ans = max(ans, sum[i] - a[i].first - pq.top());
}
ans = max(ans, a[i].second);
pq.push({sum[i - 1] - a[i].first});
}
cout << ans;
}
/*
*/
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... |