Submission #934367

# Submission time Handle Problem Language Result Execution time Memory
934367 2024-02-27T08:23:03 Z alexander707070 Candies (JOI18_candies) C++14
0 / 100
5 ms 2392 KB
#include<bits/stdc++.h>
#define MAXN 500007
using namespace std;

const long long inf=1e17;

struct node{
    int l,r;
    int from,to;
    int res;
};

int n,best;
long long a[MAXN],sum,maxs,curr;
bool used[MAXN];

long long even[MAXN],odd[MAXN];
node w[MAXN];

void erasev(int x){
    w[w[x].l].r=w[x].r;
    w[w[x].r].l=w[x].l;
}

int summ(int l,int r){
    int res=0;
    for(int i=l;i<=r;i+=2){
        res+=a[i];
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

        w[i]={i-1,i+1,i,i,a[i]};
    }

    w[0].r=1;
    w[n+1].l=n;

    for(int i=1;i<=n/2+n%2;i++){
        curr=0; maxs=-inf;

        while(true){
            curr=w[curr].r;
            if(curr==n+1)break;
            
            if(w[curr].res>maxs){
                maxs=w[curr].res; best=curr;
            }

        }

        sum+=maxs;

        if(w[best].l==0){
            erasev(w[best].r);
            erasev(best);
        }else if(w[best].r==n+1){
            erasev(w[best].l);
            erasev(best);
        }else{
            w[best].from=w[w[best].l].from;
            w[best].to=w[w[best].r].to;

            w[best].res=summ(w[best].from,w[best].to)-summ(w[best].from+1,w[best].to-1);

            erasev(w[best].l);
            erasev(w[best].r);
        }
        
        cout<<sum<<"\n";
    }

    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:43:30: warning: narrowing conversion of 'a[i]' from 'long long int' to 'int' [-Wnarrowing]
   43 |         w[i]={i-1,i+1,i,i,a[i]};
      |                           ~~~^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -