結果

問題 No.393 2本の竹
ユーザー togari_takamototogari_takamoto
提出日時 2016-07-12 07:09:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 1,000 ms
コード長 865 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 174,196 KB
実行使用メモリ 45,936 KB
最終ジャッジ日時 2023-08-08 00:06:59
合計ジャッジ時間 3,764 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 231 ms
43,884 KB
testcase_10 AC 69 ms
15,868 KB
testcase_11 AC 84 ms
16,732 KB
testcase_12 AC 93 ms
18,576 KB
testcase_13 AC 60 ms
12,412 KB
testcase_14 AC 41 ms
10,900 KB
testcase_15 AC 26 ms
16,772 KB
testcase_16 AC 72 ms
27,276 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 112 ms
22,776 KB
testcase_23 AC 59 ms
15,984 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 196 ms
45,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define ALL(c) (c).begin(), (c).end()

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	ll d; cin >> d;
	REP(_, d) {
		ll n1, n2, m; cin >> n1 >> n2 >> m;
		vl a(m); REP(i, m) cin >> a[i];
		sort(ALL(a));
		vvl dp(m + 1, vl(n1 + 1, n2 + 1));
		dp[0][0] = 0; // dp[i人までで][n1のうちk利用するときの] = n2の利用した最小の長さ
		FOR(i, 1, m + 1) REP(k, n1 + 1) {
			if(k - a[i - 1] >= 0) dp[i][k] = min(dp[i][k], dp[i - 1][k - a[i - 1]]);
			dp[i][k] = min(dp[i][k], dp[i - 1][k] + a[i - 1]);
		}

		ll ans = 0;
		REP(i, m + 1) REP(j, n1 + 1) if (dp[i][j] <= n2) ans = max(ans, i);
		cout << ans << endl;
	}
	return 0;
}
0