結果

問題 No.393 2本の竹
ユーザー koba-e964koba-e964
提出日時 2016-12-07 14:31:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 94 ms / 1,000 ms
コード長 1,376 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 91,632 KB
実行使用メモリ 27,344 KB
最終ジャッジ日時 2023-08-18 19:44:13
合計ジャッジ時間 3,491 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
21,916 KB
testcase_01 AC 14 ms
7,732 KB
testcase_02 AC 38 ms
23,812 KB
testcase_03 AC 31 ms
13,584 KB
testcase_04 AC 20 ms
13,584 KB
testcase_05 AC 22 ms
11,600 KB
testcase_06 AC 17 ms
9,492 KB
testcase_07 AC 33 ms
13,880 KB
testcase_08 AC 57 ms
19,784 KB
testcase_09 AC 94 ms
26,044 KB
testcase_10 AC 31 ms
11,532 KB
testcase_11 AC 47 ms
13,656 KB
testcase_12 AC 51 ms
15,840 KB
testcase_13 AC 42 ms
13,596 KB
testcase_14 AC 34 ms
13,716 KB
testcase_15 AC 8 ms
9,564 KB
testcase_16 AC 12 ms
9,628 KB
testcase_17 AC 36 ms
19,796 KB
testcase_18 AC 20 ms
13,724 KB
testcase_19 AC 11 ms
9,692 KB
testcase_20 AC 18 ms
9,488 KB
testcase_21 AC 30 ms
19,856 KB
testcase_22 AC 53 ms
15,720 KB
testcase_23 AC 29 ms
13,592 KB
testcase_24 AC 20 ms
9,472 KB
testcase_25 AC 17 ms
9,544 KB
testcase_26 AC 12 ms
9,612 KB
testcase_27 AC 89 ms
27,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int M = 61;
const int W = 100100;
int dp[M][W];

int solve(int n1, int n2, const VI &a) {
  int m = a.size();
  REP(i, 0, W) {
    dp[0][i] = 0;
  }
  dp[0][0] = 1;
  int tot = 0;
  REP(i, 0, m) {
    tot += a[i];
    REP(j, 0, W) { dp[i + 1][j] = dp[i][j]; }
    REP(j, 0, W) {
      if (j >= a[i]) {
	dp[i + 1][j] |= dp[i][j - a[i]];
      }
    }
    bool ok = 0;
    REP(j, 0, n1 + 1) {
      if (dp[i + 1][j] && tot - j <= n2) {
	ok = 1;
      }
    }
    if (not ok) {
      return i;
    }
  }
  return m;
}

int main(void){
  int d;
  cin >> d;
  while(d--) {
    int n1, n2;
    cin >> n1 >> n2;
    int m;
    cin >> m;
    VI a(m);
    REP(i, 0, m) { cin >> a[i]; }
    sort(a.begin(), a.end());
    cout << solve(n1, n2, a) << endl;
  }
}
0