結果

問題 No.393 2本の竹
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-13 14:50:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 849 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 166,536 KB
実行使用メモリ 27,620 KB
最終ジャッジ日時 2024-04-25 18:20:21
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
20,096 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 5 ms
24,144 KB
testcase_03 AC 4 ms
13,916 KB
testcase_04 AC 4 ms
11,996 KB
testcase_05 AC 3 ms
9,956 KB
testcase_06 AC 2 ms
7,780 KB
testcase_07 AC 3 ms
14,204 KB
testcase_08 AC 5 ms
20,216 KB
testcase_09 AC 58 ms
27,148 KB
testcase_10 AC 13 ms
10,668 KB
testcase_11 AC 20 ms
16,848 KB
testcase_12 AC 24 ms
18,788 KB
testcase_13 AC 15 ms
18,140 KB
testcase_14 AC 10 ms
16,252 KB
testcase_15 AC 10 ms
26,724 KB
testcase_16 AC 17 ms
24,968 KB
testcase_17 AC 4 ms
16,124 KB
testcase_18 AC 4 ms
11,888 KB
testcase_19 AC 3 ms
7,772 KB
testcase_20 AC 3 ms
7,908 KB
testcase_21 AC 5 ms
18,144 KB
testcase_22 AC 29 ms
14,300 KB
testcase_23 AC 14 ms
14,548 KB
testcase_24 AC 3 ms
12,024 KB
testcase_25 AC 3 ms
9,944 KB
testcase_26 AC 3 ms
7,900 KB
testcase_27 AC 49 ms
27,620 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