結果

問題 No.3670 Fast Knapsack
コンテスト
ユーザー tnakao0123
提出日時 2026-09-06 11:49:55
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 333 ms
コンパイル使用メモリ 76,504 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-06 11:50:09
合計ジャッジ時間 11,794 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3670.cc:  No.3670 Fast Knapsack - yukicoder
 */

#include<cstdio>
#include<bitset>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_S = 200000;

/* typedef */

using btst = bitset<MAX_S + 1>;

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n, s;
    scanf("%d%d", &n, &s);
    for (int i = 0; i < n; i++) scanf("%d", as + i);

    btst dp;
    dp[0] = 1;

    for (int i = 0; i < n; i++) dp |= (dp << as[i]);

    int maxs = 0;
    for (int i = s; i > 0; i--)
      if (dp[i]) { maxs = i; break; }

    printf("%d\n", maxs);
  }

  return 0;
}

0