Source Code
#include <stdio.h>

int main(){
    long long n,k;
    scanf("%lld%lld",&n,&k);
    long long a[n],b[n];
    for(int i = 0; i < n; i++){
        scanf("%lld",&a[i]);
        b[i] = a[i];
    }
    long long i = 0,count = 0,flag = 0, c = 2;
    while(k >= b[i]){
        k-=b[i];
        b[i]+=a[i];
        count ++;
        if(n == 1) continue;
        if(i == 1 || i == n-2) c = 3;
        else if(i == n-1 && c == 3) {flag = 1;
        c = 2;
        continue;}
        else if(i == 0  && c == 3) {flag = 0; continue;
            c = 2;
        }
        else if(flag == 1) i--;
        else if(flag == 0) i++;
    }
    printf("%lld",count);
}
Copy
Saqqa 26/40 Ayoooy
GNU G++17
11 ms
2.3 MB
Wrong Answer