結果

問題 No.393 2本の竹
ユーザー furafura
提出日時 2020-07-31 02:13:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 997 ms / 1,000 ms
コード長 607 bytes
コンパイル時間 2,729 ms
コンパイル使用メモリ 204,568 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 14:14:02
合計ジャッジ時間 7,475 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 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 4 ms
4,380 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 997 ms
4,380 KB
testcase_10 AC 66 ms
4,376 KB
testcase_11 AC 167 ms
4,384 KB
testcase_12 AC 243 ms
4,380 KB
testcase_13 AC 103 ms
4,384 KB
testcase_14 AC 41 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 320 ms
4,376 KB
testcase_23 AC 79 ms
4,380 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 951 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

void solve(){
	int n1,n2,m; scanf("%d%d%d",&n1,&n2,&m);
	vector<int> a(m);
	rep(i,m) scanf("%d",&a[i]);

	sort(a.begin(),a.end());

	int ans=0;
	rep(i,m){
		int sum=accumulate(a.begin(),a.begin()+i+1,0);
		if(sum>n1+n2) break;

		vector<bool> dp(sum+1);
		dp[0]=true;
		rep(j,i+1){
			for(int x=sum;x>=a[j];x--) if(dp[x-a[j]]) dp[x]=true;
		}
		bool ok=false;
		rep(x,n1+1) if(dp[x] && sum-x<=n2) ok=true;
		if(ok) ans=i+1;
	}
	printf("%d\n",ans);
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0