(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.append(0)
days = 0
candies = 0
while days < n:
if a[days] <= 8:
candies += a[days]
else:
candies += 8
a[days + 1] += a[days] - 8
days += 1
if candies >= k:
break
if candies < k:
print('-1')
else:
print(days)
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long int
ll binaryToDecimal(string n)
{
string num = n;
int dec_value = 0;
// Initializing base value to 1, i.e 2^0
int base = 1;
int len = num.length();
for (int i = len - 1; i >= 0; i--)
{
if (num[i] == '1')
dec_value += base;
base = base * 2;
}
return dec_value;
}
string DecimalToBinary(ll num)
{
string str;
while (num)
{
if (num & 1) // 1
str += '1';
else // 0
str += '0';
num >>= 1; // Right Shift by 1
}
return str;
}
void solve()
{
ll n,k;
cin>>n>>k;
ll arr[100];
ll sum=0;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
sum+=arr[i];
}
ll count=0;
ll sum2=0;
for(ll i=0;i<n;i++)
{
arr[i]+=sum2;
if(arr[i]>8)
{
k-=8;
sum2=arr[i]-8;
count++;
}
else
{
k-=arr[i];
sum2=0;
count++;
}
if(k<=0)
{
cout<<count<<endl;
return;
}
}
cout<<"-1"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
}
1629C - Meximum Array | 1629D - Peculiar Movie Preferences |
1629E - Grid Xor | 1629F1 - Game on Sum (Easy Version) |
2148. Count Elements With Strictly Smaller and Greater Elements | 2149. Rearrange Array Elements by Sign |
2150. Find All Lonely Numbers in the Array | 2151. Maximum Good People Based on Statements |
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |
1630A - And Matching | 1630B - Range and Partition |
1630C - Paint the Middle | 1630D - Flipping Range |
1328A - Divisibility Problem | 339A - Helpful Maths |
4A - Watermelon | 476A - Dreamoon and Stairs |
1409A - Yet Another Two Integers Problem | 977A - Wrong Subtraction |
263A - Beautiful Matrix | 180C - Letter |
151A - Soft Drinking | 1352A - Sum of Round Numbers |
281A - Word Capitalization | 1646A - Square Counting |
266A - Stones on the Table | 61A - Ultra-Fast Mathematician |
148A - Insomnia cure | 1650A - Deletions of Two Adjacent Letters |