Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
703 B
3
Indexable
Never
#include <stdio.h>
int a[200005]={0};
int b[200005]={0};
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    if(b[1]>=n/2){printf("0"); return 0;}
    long long sum1,sum2;
    long long max=0;
    long long dem=0;
    for(int i=0;i<n;i++){
        sum1 =a[i];
        sum2 =a[i];
        for(int x=i;x<n;){
            x=x+a[x];
            if(x>=n){break;}
            sum1=sum1+a[x];
        }
        for(int y=i;y<n;){
            y=y-a[y];
            if(y<0){break;}
            sum2=sum2+a[y];
        }     
        if(sum1>max){max=sum1;dem=i;}
        if(sum2>max){max=sum2;dem=i;}
    }
    printf("%lld",dem);
}