-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path839A.cpp
More file actions
43 lines (41 loc) · 696 Bytes
/
Copy path839A.cpp
File metadata and controls
43 lines (41 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
int main()
{
int n,k,i,arr[150],j=-1,c=0,sum=0;
cin >> n >> k;
for(i=0;i<n;i++)
{
cin >> arr[i];
}
for(i=0;i<n;i++)
{
if(arr[i]>=8 && k > 0)
{
k -= 8;
c++;
sum += (arr[i]-8);
}
else if(arr[i]<8 && k > 0)
{
if(sum >= (8-arr[i]) || k <= sum+arr[i])
{
sum -= (8-arr[i]);
k -= 8;
}
else
{
k -= arr[i];
}
c++;
}
}
if(k <= 0)
{
cout << c;
}
else
{
cout << j;
}
}