問題一覧 > 通常問題

No.617 Nafmo Goes Shopping

レベル : / AI推定難易度 : 208 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 303
作問者 : Nafmo2 / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 2021 / 自分の提出
問題文最終更新日: 2025-08-27 00:43:41
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
Advent Calendar Contest 2017 (順位表) の他の問題:

Problem Statement

Nafmo organized an event called CombNaf.
(CombNaf actually takes place on the day this problem is published. There will also be a Niconico Live broadcast.)
So he is going out to buy refreshments for the event.

At the store, he found $N$ items that looked good.
Each item has a weight $A_i$.
Nafmo can carry a total weight of at most $K$.

Nafmo usually chooses with cost performance in mind, but
this time he received $5000$ trillion yen from an oil magnate,
so he can buy things without worrying about the cost.

When Nafmo selects items so that the total weight is maximized within what he can carry,
output the total weight.
Note that Nafmo has little time left before CombNaf,
so he cannot go to the store, return to the venue, and then go back to the store once more.
(This means that he cannot make two round trips to carry $2K$.)

Input

$N \ K$
$A_1$
$A_2$ 
$\dots$ 
$A_N$

$1 \le N \le 20 $
$0 \le K \le 2 \times 10^6 $
$ 1 \le A_i \le 10^5$

Output

Output the total weight of the selected items.
Print a newline at the end.

Sample

Sample 1
Input
2 4
2
3
Output
3

Select nothing: 0
$A_1$: 2
$A_2$: 3
$A_1,A_2$: 5
Among these, the maximum that he can carry is 3, so output 3.

Sample 2
Input
4 4
1
2
3
5
Output
4


The maximum value 4 is attained when $i = 1,3$.

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