CF 839A

来源:互联网 发布:机床的重要性 知乎 编辑:程序博客网 时间:2024/06/09 16:21

Discription

给定n天,每天有a[i]个蛋糕。小明一共需要k个蛋糕,每天给小明的蛋糕数量<=8,如果今天给了小明8个蛋糕后有剩余,可以将剩余的蛋糕积攒到明天,以此类推,问小明最少几天能得到k个蛋糕。

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, …, an (1 ≤ ai ≤ 100).

Output

如果在n天内小明得不到足够的蛋糕,输出-1

Examples

input
2 3
1 2
output
2
input
3 17
10 10 10
output
3
input
1 9
10
output
-1

Code

#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>using namespace std;int a[111];int main(){    // freopen("in.txt", "r", stdin);    int n, k;    while (~scanf("%d%d", &n, &k))    {        for (int i = 0; i < n; i++)            scanf("%d", &a[i]);        int ans = -1;        for (int i = 0; i < n; i++)        {            int t = min(a[i], 8);            a[i + 1] += (a[i] - t);            k -= t;            if (k <= 0)            {                ans = i;                break;            }        }        if (ans == -1)            printf("-1\n");        else            printf("%d\n", ans + 1);    }    return 0;}
原创粉丝点击