No.156 Candy Box
タグ : / 解いたユーザー数 676
作問者 :
nmnmnmnmnmnmnm
Problem Statement
There are $N$ boxes containing candies.
The $i$-th box contains $C_i$ candies.
A-kun takes one candy from the box that has the fewest candies at that moment.
He repeats this until he has taken a total of $M$ candies.
How many boxes are empty when $M$ candies have been taken out?
Input
$N$ $M$ $C_1$ $C_2$ $\dots$ $C_N$
$1 \le N \le 10$
$1 \le M \le 1000000$
$1 \le C_i \le 100000$
$M$ is given as a number not exceeding the initial total number of candies.
Output
Output on one line the number of boxes that are empty after $M$ candies have been taken.
Do not forget the newline at the end.
Sample
Sample 1
Input
3 2 1 2 3
Output
1
There are 3 boxes of candies.
The first box contains 1 candy.
The second box contains 2 candies.
The third box contains 3 candies.
A-kun will now take a total of 2 candies.
A-kun first takes 1 candy from the box containing 1 candy.
Next, he takes 1 candy from the box containing 2 candies.
The first box contains 0 candies.
The second box contains 1 candy.
The third box contains 3 candies.
The number of empty candy boxes left at the end is 1.
Sample 2
Input
3 2 1 1 3
Output
2
There are 3 boxes of candies.
The first box contains 1 candy.
The second box contains 1 candy.
The third box contains 3 candies.
A-kun will now take a total of 2 candies.
A-kun first takes 1 candy from a box containing 1 candy.
Next, he takes 1 candy from the other box containing 1 candy.
The first box contains 0 candies.
The second box contains 0 candies.
The third box contains 3 candies.
The number of empty candy boxes left at the end is 2.
Sample 3
Input
4 10 3 2 4 1
Output
4
All the boxes become empty.
Sample 4
Input
6 257109 53771 46578 31908 80435 62678 4327
Output
5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。