Submission #1049940

# Submission time Handle Problem Language Result Execution time Memory
1049940 2024-08-09T06:15:45 Z vjudge1 Art Exhibition (JOI18_art) C++17
100 / 100
184 ms 28244 KB
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#include <bits/stdc++.h>
#define ll long long int
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define TxtIO freopen("lol.in","r",stdin); freopen("lol.txt","w",stdout);
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
using namespace std;

struct segtree{
    vector <ll> tree;
    ll size;
    void init(ll n){
        size=1;
        while(size<n) size*=2;
        tree.assign(2*size-1,-1e18);
    }

    void build(vector <pair<ll,ll>> &a,ll x,ll lx,ll rx){
        if(rx-lx==1){
            if(lx<a.size()) tree[x]=a[lx].second-a[lx].first;
            return;
        }
        else{
            ll m=(lx+rx)/2;
            build(a,x*2+1,lx,m);
            build(a,x*2+2,m,rx);
            tree[x]=max(tree[x*2+1],tree[x*2+2]);
        }
    }

    void build(vector <pair<ll,ll>> &a){
        init(a.size());
        build(a,0,0,size);
    }

    ll maxdo(ll l, ll r, ll x, ll lx, ll rx){
        if(lx>=r || l>=rx) return -1e18;
        if(lx>=l && rx<=r) return tree[x];
        ll m=(lx+rx)/2;
        ll s1=maxdo(l,r,x*2+1,lx,m);
        ll s2=maxdo(l,r,x*2+2,m,rx);
        return max(s1,s2);
    }

    ll maxdo(ll l,ll r){
        return maxdo(l,r,0,0,size);
    }
};

void solve(){
    ll n;
    cin>>n;
    vector <pair<ll,ll>> a(n);
    forn(i,n) cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end());
    vector <ll> p(n);p[0]=a[0].second;
    for(int i=1;i<n;i++){
        p[i]=p[i-1]+a[i].second;
    }
    vector <pair<ll,ll>> lol(n);
    for(int i=0;i<n;i++){
        lol[i].first=a[i].first;
        lol[i].second=p[i];
    }
    segtree st;
    st.build(lol);
    ll ans=-1e18;
    for(int l=0;l<n;l++){
        ll pl,al=a[l].first;
        if(l==0) pl=0;
        else pl=p[l-1];
        ans=max(ans,st.maxdo(l,n)-pl+al);
    }
    cout<<ans;
}

signed main(){
    speed;
    int t=1;
    while(t--){
        solve();
    }
}

Compilation message

art.cpp: In member function 'void segtree::build(std::vector<std::pair<long long int, long long int> >&, long long int, long long int, long long int)':
art.cpp:24:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |             if(lx<a.size()) tree[x]=a[lx].second-a[lx].first;
      |                ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 408 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 408 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 408 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 608 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 660 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 608 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 796 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 408 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 608 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 660 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 608 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 796 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 148 ms 27988 KB Output is correct
53 Correct 136 ms 28000 KB Output is correct
54 Correct 136 ms 27984 KB Output is correct
55 Correct 152 ms 28004 KB Output is correct
56 Correct 163 ms 28244 KB Output is correct
57 Correct 140 ms 27984 KB Output is correct
58 Correct 137 ms 27984 KB Output is correct
59 Correct 138 ms 27988 KB Output is correct
60 Correct 142 ms 27984 KB Output is correct
61 Correct 135 ms 27984 KB Output is correct
62 Correct 144 ms 27988 KB Output is correct
63 Correct 135 ms 27988 KB Output is correct
64 Correct 152 ms 27984 KB Output is correct
65 Correct 157 ms 27984 KB Output is correct
66 Correct 136 ms 28240 KB Output is correct
67 Correct 137 ms 27984 KB Output is correct
68 Correct 184 ms 27988 KB Output is correct