結果

問題 No.393 2本の竹
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-13 14:50:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 1,000 ms
コード長 849 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 167,140 KB
実行使用メモリ 27,368 KB
最終ジャッジ日時 2023-08-08 00:15:49
合計ジャッジ時間 2,933 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
19,820 KB
testcase_01 AC 2 ms
5,716 KB
testcase_02 AC 5 ms
22,000 KB
testcase_03 AC 4 ms
13,808 KB
testcase_04 AC 3 ms
11,744 KB
testcase_05 AC 3 ms
9,664 KB
testcase_06 AC 3 ms
7,736 KB
testcase_07 AC 3 ms
13,748 KB
testcase_08 AC 5 ms
19,908 KB
testcase_09 AC 52 ms
27,108 KB
testcase_10 AC 13 ms
11,516 KB
testcase_11 AC 19 ms
15,144 KB
testcase_12 AC 23 ms
19,352 KB
testcase_13 AC 15 ms
16,816 KB
testcase_14 AC 10 ms
16,436 KB
testcase_15 AC 9 ms
25,012 KB
testcase_16 AC 16 ms
25,580 KB
testcase_17 AC 4 ms
15,728 KB
testcase_18 AC 3 ms
11,708 KB
testcase_19 AC 2 ms
5,516 KB
testcase_20 AC 2 ms
7,656 KB
testcase_21 AC 4 ms
17,776 KB
testcase_22 AC 27 ms
15,808 KB
testcase_23 AC 13 ms
13,052 KB
testcase_24 AC 4 ms
9,696 KB
testcase_25 AC 2 ms
7,568 KB
testcase_26 AC 2 ms
7,636 KB
testcase_27 AC 46 ms
27,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


int d;
int n1, n2, m;
int A[61];
//-----------------------------------------------------------------
int dp[61][101010];

void solve() {
	scanf("%d %d %d", &n1, &n2, &m);
	rep(i, 0, m) scanf("%d", &A[i]);
	sort(A, A + m);

	rep(i, 0, m + 1) rep(j, 0, n1 + 1) dp[i][j] = -1;
	dp[0][n1] = 0;

	int sum = 0;
	int ans = 0;
	rep(i, 0, m) {
		
		rep(j, 0, n1 + 1) if (0 <= dp[i][j]) {
			ans = max(ans, dp[i][j]);

			int jj = n2 - (sum - (n1 - j));

			if (A[i] <= j) dp[i + 1][j - A[i]] = dp[i][j] + 1;
			if (A[i] <= jj) dp[i + 1][j] = dp[i][j] + 1;
		}
		sum += A[i];
	}
	rep(i, 0, n1 + 1) ans = max(ans, dp[m][i]);

	cout << ans << endl;
}
//-----------------------------------------------------------------
int main() {
	scanf("%d", &d);
	rep(i, 0, d) solve();
}
0