結果

問題 No.50 おもちゃ箱
ユーザー furafura
提出日時 2020-06-07 08:50:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 577 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 200,380 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 03:56:32
合計ジャッジ時間 4,444 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;

const int INF=1<<29;

int n,m,a[10],b[10];

int cap[10];

int dfs(int i){
	if(i==n) return m-count(cap,cap+m,0);

	int res=INF;
	rep(j,m) if(cap[j]+a[i]<=b[j]) {
		cap[j]+=a[i];
		res=min(res,dfs(i+1));
		cap[j]-=a[i];
		if(cap[j]==0) break;
	}
	return res;
}

int main(){
	scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);
	scanf("%d",&m);
	rep(j,m) scanf("%d",&b[j]);

	sort(a,a+n,greater<int>());
	sort(b,b+m,greater<int>());

	int ans=dfs(0);
	printf("%d\n",ans<INF?ans:-1);

	return 0;
}
0