結果

問題 No.3670 Fast Knapsack
コンテスト
ユーザー harurun
提出日時 2026-08-05 01:39:16
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 625 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,330 ms
コンパイル使用メモリ 351,448 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-04 22:01:13
合計ジャッジ時間 13,380 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 WA * 12 TLE * 2 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

constexpr int MAX_S = 100000;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    while (T--) {
        int N, S;
        cin >> N >> S;

        bitset<MAX_S + 1> reachable;
        reachable[0] = true;

        for (int i = 0; i < N; ++i) {
            int a;
            cin >> a;

            if (a <= S) {
                reachable |= reachable << a;
            }
        }

        int answer = S;
        while (!reachable[answer]) {
            --answer;
        }

        cout << answer << '\n';
    }

    return 0;
}
0