結果

問題 No.617 Nafmo、買い出しに行く
ユーザー wxy40wxy40
提出日時 2020-01-16 14:24:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 71,096 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 22:56:00
合計ジャッジ時間 1,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 68 ms
4,376 KB
testcase_07 AC 68 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 68 ms
4,376 KB
testcase_11 AC 67 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int N;
long K;
std::vector<long> v;

int main() {
    std::cin >> N >> K;
    v.resize(N);
    for (int i = 0; i < N; ++i) std::cin >> v[i];
    int weight = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        int tmp_weight = 0;
        for (int i = 0; i < N; ++i) if (bit & (1 <<  i)) tmp_weight += v[i];

        if (tmp_weight <= K) weight = std::max(weight, tmp_weight);
        else break;
    }
    std::cout << weight << std::endl;

    return 0;
}
0