結果

問題 No.393 2本の竹
ユーザー siman
提出日時 2021-09-05 02:31:53
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 1,000 ms
コード長 1,097 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 143,360 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-21 17:40:00
合計ジャッジ時間 3,280 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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