Codeforces 839A Arya and Bran

Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.

At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don‘t give him the candies at the same day, they are saved for her and she can give them to him later.

Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).

Print -1 if she can‘t give him k candies during n given days.

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

If it is impossible for Arya to give Bran k candies within n days, print -1.

Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.

Examples

input

2 31 2

output

2

input

3 1710 10 10

output

3

input

1 910

output

-1

Note

In the first sample, Arya can give Bran 3 candies in 2 days.

In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.

In the third sample, Arya can‘t give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.



  题目大意 有n天,在第i天Arya能够神奇地得到ai颗糖,(为了防止Bran吃糖吃多了蛀牙,所以)每天Arya最多能给Bran 8颗糖,问在最早在哪一天,Bran总共得到k颗糖。

  每天能给多少就给多少。

Code

 1 /**
 2  * Codeforces
 3  * Problem#839D
 4  * Accepted
 5  * Time: 171ms
 6  * Memory: 15400k
 7  */
 8 #include <bits/stdc++.h>
 9 using namespace std;
10
11 const int lim = 1e6 + 1;
12 const int moder = 1e9 + 7;
13
14 int n;
15 int *a;
16 int *pow2;
17 int cnt[lim], counter[lim];
18 int f[lim];
19 int res = 0;
20
21 inline void init() {
22     scanf("%d", &n);
23     a = new int[(n + 1)];
24     pow2 = new int[(n + 1)];
25     pow2[0] = 1;
26     for(int i = 1; i <= n; i++) {
27         scanf("%d", a + i);
28         counter[a[i]]++;
29         pow2[i] = (pow2[i - 1] << 1) % moder;
30     }
31 }
32
33 inline void solve() {
34     for(int i = 1; i < lim; i++)
35         for(int j = i; j < lim; j += i)
36             cnt[i] += counter[j];
37
38     for(int i = lim - 1; i > 1; i--) {
39         if(!cnt[i])    continue;
40         f[i] = (cnt[i] * 1LL * pow2[cnt[i] - 1]) % moder;
41         for(int j = i << 1; j < lim; j += i)
42             f[i] = (f[i] - f[j]) % moder;
43         if(f[i] < 0)    f[i] += moder;
44         res = (res + (f[i] * 1LL * i) % moder) % moder;
45     }
46
47     printf("%d\n", res);
48 }
49
50 int main() {
51     init();
52     solve();
53     return 0;
54 }
时间: 2024-12-18 17:21:17

Codeforces 839A Arya and Bran的相关文章

codeforce 839A Arya and Bran(水题)

Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by

Round #428 A. Arya and Bran(Div.2)

Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by

Codeforces Round #428 (Div. 2) A-C

A. Arya and Bran 水题 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> using namespace

Codeforces Round #428A

Arya and Bran 题意:A每天可以得到ai颗糖,每天A最多可以给B8颗糖,A的糖可以结余,问最少多少天可以B可以得到k颗糖 思路:没什么好说的 AC代码: #include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store