| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 127254 | AuldLangSyne | Art Exhibition (JOI18_art) | C++14 | 2 ms | 376 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>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
const int N = 5e5+7;
ll n, ans = 0, b[N], f[N], rmq[N][19];
ii a[N];
ll get_min(int post){
int loga;
if(loga > 1) loga = log2(post-1);
else loga = 0;
return min(rmq[0][loga], rmq[post-(1<<loga)][loga]);
}
signed main(){
scanf("%d", &n);
f(i,1,n){
scanf("%lld %lld", &a[i].x, &a[i].y);
}
sort(a+1, a+1+n);
rmq[0][0] = -a[1].x;
f(i,1,n){
f[i] = f[i-1] + a[i].y;
b[i] = f[i]-a[i].x;
if(i != n){
rmq[i][0] = f[i]-a[i+1].x;
}
}
f(j,1,18){
ff(i,0,n){
if(i + (1<<j) - 1 < n){
rmq[i][j] = min(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
}
}
}
f(i,1,n){
ans = max(ans, b[i]-get_min(i));
}
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... | ||||
