#include<iostream>
using namespace std;
#define MAX_N 100010
int main(){
int a[MAX_N];
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
}
int count=0;
int pos=1;
int i;
for( i=1;i<=n;i++){
if(a[i]<=8)
count+=a[i];
else{
count+=8;
if(i<=n-1){
a[i+1]+=a[i]-8;
}
}
if(count>=k){
pos=i;
break;
}
}
if(i==n+1) printf("-1");
else printf("%d",pos);
}
Codeforces Round #428 (Div. 2) A. Arya and Bran
最新推荐文章于 2022-11-22 23:15:14 发布