Submission #102132

# Submission time Handle Problem Language Result Execution time Memory
102132 2019-03-22T18:05:27 Z Leonardo_Paes Hacker (BOI15_hac) C++11
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e5+10;

int vet[MAXN], v[MAXN], tree[4*MAXN];

void build(int node, int l, int r){

    if(l==r){
        tree[node]=v[l];
        return;
    }

    int mid = (l+r)>>1;

    build(2*node, l, mid);
    build(2*node+1, mid+1, r);

    tree[node] = min(tree[2*node], tree[2*node+1]);
}

int query(int node, int tl, int tr, int l, int r){

    if(tr<l or tl>r){
        return 3000;
    }

    if(tl>=l and tr<=r){
        return tree[node];
    }

    int mid = (tl+tr)>>1;

    int op1 = query(2*node, tl, mid, l, r);
    int op2 = query(2*node+1, mid+1, tr, l, r);

    return min(op1, op2);
}

int main(){

    int n, k, resp=0;

    cin >> n;

    k = ceil((double)n/2);

    for(int i=1; i<=n; i++){
        cin >> vet[i];
    }

    build(1, 1, n);

    int sum=0;

    for(int i=n-k+2; ;i++){
        if(i==2)break;
        if(i==n+1)i=1;
        sum+=vet[i];
    }

    v[1]=sum;

    for(int i=n-k+3, q=2; q<=n+k-1; i++, q++){
        int j=q;
        if(i==n+1)i=1;
        if(j>n)j-=n;
        int a = i;
        int b = j;
        if(a==1)a=n+1;
        if(b==n+1)b=1;
        sum-=vet[a-1];
        sum+=vet[b];
        v[q]=sum;
    }

    build(1, 1, n);

    for(int i=1, j=k; i<=n; i++, j++){
        if(j>n)j-=n;

        int u = query(1, 1, n, min(i,j), max(i,j));

        if(u==3000)u=0;

        resp=max(resp, u);
    }
    cout << resp << endl;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -