結果
| 問題 | No.50 おもちゃ箱 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-08-20 18:13:19 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 951 bytes | 
| コンパイル時間 | 1,207 ms | 
| コンパイル使用メモリ | 162,296 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-18 10:56:05 | 
| 合計ジャッジ時間 | 2,578 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 25 WA * 13 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
int N, A[10], M, B[10];
int lim;
int used[10];
int calc(int k) {
	if (k == N) {
		int res = 0;
		rep (i, N) res += used[i] > 0;
		return res;
	}
	int res = inf;
	rep (i, lim) {
		if (B[i] >= A[k]) {
			B[i] -= A[k];
			used[i]++;
			res = min(res, calc(k + 1));
			used[i]--;
			B[i] += A[k];
		}
	}
	return res;
}
int main() {
	cin >> N;
	rep (i, N) cin >> A[i];
	cin >> M;
	rep (i, M) cin >> B[i];
	sort(B, B + N);
	reverse(B, B + N);
	int ans = inf;
	rep2 (i, 1, M + 1) {
		lim = i;	
		int c = calc(0);
		if (c != inf) {
			ans = i;
			break;		
		}
	}
	if (ans == inf) ans = -1;
	cout << ans << endl;
	return 0;
}
            
            
            
        