Submission #720821

# Submission time Handle Problem Language Result Execution time Memory
720821 2023-04-09T11:23:08 Z Ahmed57 Hacker (BOI15_hac) C++14
100 / 100
270 ms 22732 KB
#include <bits/stdc++.h>

using namespace std;
int n;long long arr[500001];
long long st[500001];
long long pref[500001];
long long seg[2000001];
long long ge(int l,int r){
    if(r>=l){
        return pref[r]-(l==0?0:pref[l-1]);
    }else{
        return (pref[n-1]-(l==0?0:pref[l-1]))+pref[r];
    }
}
void build(int p,int l,int r){
    if(l==r){
        seg[p] = st[l-1];
        return ;
    }
    int md = (l+r)/2;
    build(p*2,l,md);
    build(p*2+1,md+1,r);
    seg[p]= max(seg[p*2],seg[p*2+1]);
}
long long query(int p,int l,int r,int lq,int rq){
    if(l>=lq&&r<=rq)return seg[p];
    if(l>rq||r<lq)return 0;
    int md = (l+r)/2;
    return max(query(p*2,l,md,lq,rq),query(p*2+1,md+1,r,lq,rq));
}
long long val(int l,int r){
    if(r>=l){
        return query(1,1,n,l+1,r+1);
    }else{
        return max(query(1,1,n,l+1,n),query(1,1,n,1,r+1));
    }
}
signed main(){
    cin>>n;
    int seg = n/2;
    for(int i = 0;i<n;i++){
        cin>>arr[i];
        pref[i] = arr[i];
        if(i)pref[i]+=pref[i-1];
    }for(int i = 0;i<n;i++){
        st[i] = ge(i,(i+seg-1)%n);
    }
    build(1,1,n);
    long long ans = 0;
    for(int i = 0;i<n;i++){
        long long l = (i+1)%n;
        long long r = ((i-seg)%n+n)%n;
        ans = max(ans,pref[n-1]-val(l,r));
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 3 ms 576 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 572 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 516 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 580 KB Output is correct
4 Correct 44 ms 4584 KB Output is correct
5 Correct 96 ms 9812 KB Output is correct
6 Correct 123 ms 11340 KB Output is correct
7 Correct 172 ms 16848 KB Output is correct
8 Correct 261 ms 22440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 3 ms 576 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 572 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 516 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 3 ms 580 KB Output is correct
35 Correct 44 ms 4584 KB Output is correct
36 Correct 96 ms 9812 KB Output is correct
37 Correct 123 ms 11340 KB Output is correct
38 Correct 172 ms 16848 KB Output is correct
39 Correct 261 ms 22440 KB Output is correct
40 Correct 5 ms 868 KB Output is correct
41 Correct 10 ms 1284 KB Output is correct
42 Correct 18 ms 1684 KB Output is correct
43 Correct 143 ms 9932 KB Output is correct
44 Correct 240 ms 22344 KB Output is correct
45 Correct 43 ms 5044 KB Output is correct
46 Correct 160 ms 16868 KB Output is correct
47 Correct 264 ms 22456 KB Output is correct
48 Correct 270 ms 22732 KB Output is correct
49 Correct 258 ms 21812 KB Output is correct
50 Correct 221 ms 21932 KB Output is correct