Submission #237414

# Submission time Handle Problem Language Result Execution time Memory
237414 2020-06-06T14:16:19 Z haengsyo Art Exhibition (JOI18_art) C++14
100 / 100
300 ms 21496 KB
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
const int mxN=5e5+5;
const ll INF=1e17;
pair<ll,int> arr[mxN];
ll pref[mxN];
int n;
ll t[4*mxN];

void build(int v,int tl,int tr) {
    if(tl==tr) {
        t[v]=pref[tl];
        return;
    }
    int mid=tl+(tr-tl)/2;
    build(2*v,tl,mid);
    build(2*v+1,mid+1,tr);
    t[v]=max(t[2*v],t[2*v+1]);
}

ll qry(int v,int tl,int tr,int l,int r) {
    if(tl>r || tr<l)
        return -INF;
    if(tl>=l && tr<=r)
        return t[v];
    int mid=tl+(tr-tl)/2;
    return max(qry(2*v,tl,mid,l,r),qry(2*v+1,mid+1,tr,l,r));
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    F0R(i,n)
        cin >> arr[i].first >> arr[i].second;
    sort(arr,arr+n);
    pref[0]=arr[0].second;
    FOR(i,1,n)
        pref[i]=pref[i-1]+arr[i].second;
    F0R(i,n)
        pref[i]-=arr[i].first;
    build(1,0,n-1);
    ll best=-INF;
    F0R(i,n) {
        ll val=qry(1,0,n-1,i,n-1);
        ll bef=0;
        if(i!=0)
            bef=pref[i-1]+arr[i-1].first;
        best=max(best,val+arr[i].first-bef);
    }
    cout << best;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 8 ms 768 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 8 ms 848 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 7 ms 768 KB Output is correct
36 Correct 7 ms 768 KB Output is correct
37 Correct 7 ms 768 KB Output is correct
38 Correct 7 ms 768 KB Output is correct
39 Correct 7 ms 768 KB Output is correct
40 Correct 7 ms 768 KB Output is correct
41 Correct 7 ms 768 KB Output is correct
42 Correct 7 ms 768 KB Output is correct
43 Correct 7 ms 768 KB Output is correct
44 Correct 8 ms 768 KB Output is correct
45 Correct 7 ms 768 KB Output is correct
46 Correct 7 ms 768 KB Output is correct
47 Correct 7 ms 768 KB Output is correct
48 Correct 7 ms 768 KB Output is correct
49 Correct 7 ms 768 KB Output is correct
50 Correct 7 ms 768 KB Output is correct
51 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 8 ms 768 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 7 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 8 ms 848 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 7 ms 768 KB Output is correct
36 Correct 7 ms 768 KB Output is correct
37 Correct 7 ms 768 KB Output is correct
38 Correct 7 ms 768 KB Output is correct
39 Correct 7 ms 768 KB Output is correct
40 Correct 7 ms 768 KB Output is correct
41 Correct 7 ms 768 KB Output is correct
42 Correct 7 ms 768 KB Output is correct
43 Correct 7 ms 768 KB Output is correct
44 Correct 8 ms 768 KB Output is correct
45 Correct 7 ms 768 KB Output is correct
46 Correct 7 ms 768 KB Output is correct
47 Correct 7 ms 768 KB Output is correct
48 Correct 7 ms 768 KB Output is correct
49 Correct 7 ms 768 KB Output is correct
50 Correct 7 ms 768 KB Output is correct
51 Correct 7 ms 768 KB Output is correct
52 Correct 269 ms 21368 KB Output is correct
53 Correct 275 ms 21112 KB Output is correct
54 Correct 269 ms 21284 KB Output is correct
55 Correct 271 ms 21112 KB Output is correct
56 Correct 278 ms 21496 KB Output is correct
57 Correct 265 ms 21244 KB Output is correct
58 Correct 278 ms 21256 KB Output is correct
59 Correct 280 ms 21368 KB Output is correct
60 Correct 271 ms 21216 KB Output is correct
61 Correct 268 ms 21240 KB Output is correct
62 Correct 272 ms 21368 KB Output is correct
63 Correct 286 ms 21240 KB Output is correct
64 Correct 279 ms 21368 KB Output is correct
65 Correct 300 ms 21112 KB Output is correct
66 Correct 281 ms 21248 KB Output is correct
67 Correct 263 ms 21112 KB Output is correct
68 Correct 283 ms 21112 KB Output is correct