1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #include <cstdio> int n,k,now,ans; int main(void){ scanf ("%d%d",&n,&k); int i=1; for (;i<=n;i++){ int a; scanf ("%d",&a); if (a>8)ans+=8,now+=a-8; else if (a<=8&&!now)ans+=a; else if (now+a<=8)ans+=now+a,now=0; else ans+=8,now-=8-a; if (ans>=k)break; } if (i>n&&ans<k)printf ("-1"); else printf ("%d",i); }
|