結果

問題 No.3670 Fast Knapsack
コンテスト
ユーザー harurun
提出日時 2026-08-06 05:01:31
言語 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
結果
TLE  
実行時間 -
コード長 761 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,135 ms
コンパイル使用メモリ 176,412 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-04 22:07:35
合計ジャッジ時間 9,155 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>

using namespace std;

constexpr int MAX_S = 200000;

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> dp;
        dp[0] = 1;

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

            // 正の整数なので、a > S の要素は答えに含められない
            if (a <= S) {
                dp |= dp << a;
            }
        }

        for (int sum = S; sum >= 0; --sum) {
            if (dp[sum]) {
                cout << sum << '\n';
                break;
            }
        }
    }

    return 0;
}
0