Submission #40605

# Submission time Handle Problem Language Result Execution time Memory
40605 2018-02-05T16:07:25 Z Hassoony Hacker (BOI15_hac) C++14
100 / 100
320 ms 35580 KB
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef unsigned long long ll;
typedef double D;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=5e5+9;
int n,a[MX],sums[MX],k;
ll b[MX];
ll seg[MX*6];
void build(int node,int l,int r){
    if(l==r){
        seg[node]=b[l];
        return;
    }
    int mid=(l+r)/2;
    build(node*2,l,mid);
    build(node*2+1,mid+1,r);
    seg[node]=min(seg[node*2],seg[node*2+1]);
}
ll q(int node,int l,int r,int s,int e){
    if(l>e||r<s)return inf;
    if(l>=s&&r<=e)return seg[node];
    int mid=(l+r)/2;
    return min(q(node*2,l,mid,s,e),q(node*2+1,mid+1,r,s,e));
}
int main(){
    cin>>n;
    k=(n/2)+(n%2);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sums[i]=a[i];
        if(i)sums[i]+=sums[i-1];
    }
    for(int i=0;i<n;i++){
        if(i+k-1<n){
            b[i]=sums[i+k-1];
            if(i)b[i]-=sums[i-1];
            continue;
        }
        b[i]=sums[n-1]-sums[i-1];
        int x=k-(n-i);
        b[i]+=sums[x-1];
    }
    build(1,0,n-1);
    ll ans=0;
    for(int i=0;i<n;i++){
        ll mn=inf;
        if(i-k+1>=0){
            mn=q(1,0,n-1,i-k+1,i);
        }
        else {
            mn=q(1,0,n-1,0,i);
            int x=i+1;
            x=k-x;
            mn=min(mn,q(1,0,n-1,n-x,n-1));
        }
        ans=max(ans,mn);
    }
    cout<<ans<<endl;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:32:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 572 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 712 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 712 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 2 ms 712 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 572 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 712 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 712 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 2 ms 712 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 2 ms 764 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
21 Correct 2 ms 764 KB Output is correct
22 Correct 3 ms 836 KB Output is correct
23 Correct 3 ms 1084 KB Output is correct
24 Correct 3 ms 1084 KB Output is correct
25 Correct 3 ms 1084 KB Output is correct
26 Correct 3 ms 1084 KB Output is correct
27 Correct 2 ms 1084 KB Output is correct
28 Correct 2 ms 1084 KB Output is correct
29 Correct 2 ms 1084 KB Output is correct
30 Correct 4 ms 1084 KB Output is correct
31 Correct 3 ms 1124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1124 KB Output is correct
2 Correct 2 ms 1124 KB Output is correct
3 Correct 4 ms 1124 KB Output is correct
4 Correct 42 ms 4500 KB Output is correct
5 Correct 101 ms 9328 KB Output is correct
6 Correct 130 ms 11256 KB Output is correct
7 Correct 162 ms 17336 KB Output is correct
8 Correct 264 ms 22688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 572 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 712 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 712 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 2 ms 712 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 2 ms 764 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
21 Correct 2 ms 764 KB Output is correct
22 Correct 3 ms 836 KB Output is correct
23 Correct 3 ms 1084 KB Output is correct
24 Correct 3 ms 1084 KB Output is correct
25 Correct 3 ms 1084 KB Output is correct
26 Correct 3 ms 1084 KB Output is correct
27 Correct 2 ms 1084 KB Output is correct
28 Correct 2 ms 1084 KB Output is correct
29 Correct 2 ms 1084 KB Output is correct
30 Correct 4 ms 1084 KB Output is correct
31 Correct 3 ms 1124 KB Output is correct
32 Correct 2 ms 1124 KB Output is correct
33 Correct 2 ms 1124 KB Output is correct
34 Correct 4 ms 1124 KB Output is correct
35 Correct 42 ms 4500 KB Output is correct
36 Correct 101 ms 9328 KB Output is correct
37 Correct 130 ms 11256 KB Output is correct
38 Correct 162 ms 17336 KB Output is correct
39 Correct 264 ms 22688 KB Output is correct
40 Correct 6 ms 22688 KB Output is correct
41 Correct 12 ms 22688 KB Output is correct
42 Correct 17 ms 22688 KB Output is correct
43 Correct 105 ms 22688 KB Output is correct
44 Correct 320 ms 25992 KB Output is correct
45 Correct 49 ms 25992 KB Output is correct
46 Correct 165 ms 25992 KB Output is correct
47 Correct 246 ms 29816 KB Output is correct
48 Correct 264 ms 32324 KB Output is correct
49 Correct 247 ms 33820 KB Output is correct
50 Correct 267 ms 35580 KB Output is correct