問題一覧 > 通常問題

No.5 Number Blocks

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 2046
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 14 / 自分の提出
問題文最終更新日: 2026-06-25 10:44:47
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 5 (順位表) の他の問題:

Problem Statement

Ellen is about to play with number blocks.

Each block with a number written on it has height $1$ and width $W_i$.
(There may be multiple blocks with the same width.)

These blocks are put into a box of height 1 and width L. 

Ellen wondered how many blocks could fit into the large box.
However, she realized that there are so many combinations that it would be hard, and night seems likely to fall soon.

On her behalf, find the maximum number of blocks that can fit into the large box.

Input

$L$
$N$
$W_1 W_2 W_3\dots W_N$

The first line gives $L (1 \le L \le 10000)$, the width of the large box.
The second line gives $N(1 \le N \le 10000)$, the number of blocks.
The third line gives $Wi(1 \le Wi \le L )$, the width of each block, separated by half-width spaces.

Output

Output the computed value. Add a newline at the end.

Sample

Sample 1
Input
16
3
10 5 7
Output
2

Not all of them fit into the box of width 16, but up to 2 blocks can be put in.

Sample 2
Input
100
10
14 85 77 26 50 45 66 79 10 3
Output
5

The combination 14,26,45,10,3 gives the maximum of 5 blocks (no combination can fit 6 or more blocks)

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。