# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42090 | nonocut | Art Exhibition (JOI18_art) | C++14 | 280 ms | 87280 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 pii pair<ll,ll>
#define X first
#define Y second
const int maxn = 5e5 + 5;
const ll inf = 1e18;
int n,m;
pii p[maxn], a[maxn];
int main() {
int i,j;
ll ans = 0;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%lld%lld",&p[i].X,&p[i].Y);
sort(p,p+n);
for(i=0;i<n;i++) {
if(p[i].X!=p[i+1].X) a[m++] = p[i];
else p[i+1].Y += p[i].Y;
}
ll sum = 0, mx = -inf;
for(i=0;i<m;i++) {
mx = max(mx, a[i].X - sum);
sum += a[i].Y;
ans = max(ans, sum - a[i].X + mx);
}
printf("%lld",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... |