問題一覧 > 通常問題

No.156 Candy Box

レベル : / AI推定難易度 : 162 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 676
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 307 / 自分の提出
問題文最終更新日: 2026-06-28 21:15:43
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 88 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。