結果

問題 No.393 2本の竹
ユーザー simansiman
提出日時 2021-09-05 02:31:53
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 1,097 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 105,012 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:54:59
合計ジャッジ時間 2,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 39 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 19 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 23 ms
4,376 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 30 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int d;
  cin >> d;

  for (int t = 0; t < d; ++t) {
    int n1, n2;
    cin >> n1 >> n2;
    int m;
    cin >> m;
    vector<int> A(m);

    for (int i = 0; i < m; ++i) {
      cin >> A[i];
    }

    sort(A.begin(), A.end());
    int dp[n1 + 1][2];
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    dp[0][1] = n2;
    int ans = 0;

    for (int i = 0; i < m; ++i) {
      int a = A[i];

      for (int x = n1; x >= 0; --x) {
        if (dp[x][0] == -1) continue;

        if (x + a <= n1 && dp[x + a][0] < dp[x][0] + 1) {
          dp[x + a][0] = dp[x][0] + 1;
          dp[x + a][1] = dp[x][1];
          ans = max(ans, dp[x + a][0]);
        }

        if (dp[x][1] >= a) {
          dp[x][0] += 1;
          dp[x][1] -= a;
          ans = max(ans, dp[x][0]);
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}
0