# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60392 | gusfring | Art Exhibition (JOI18_art) | C++14 | 2 ms | 248 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;
const int MAXN = 5e3 + 5;
typedef long long ll;
#define sz first
#define val second
pair<ll, ll> C[MAXN];
ll suf[MAXN], pre[MAXN], res;
int N;
int main(){
scanf("%d", &N);
for(int i=1; i<=N; ++i) scanf("%lld %lld", &C[i].sz, &C[i].val);
sort(C + 1, C + N + 1);
for(int i=1; i<=N; ++i) pre[i] = pre[i - 1] + C[i].val;
for(int i=N; i>=1; --i) suf[i] = max(suf[i + 1], pre[i] - C[i].sz);
for(int i=1; i<=N; ++i) res = max(res, suf[i + 1] - pre[i - 1] + C[i].sz);
printf("%lld\n", 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... |