結果
| 問題 |
No.50 おもちゃ箱
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-07 17:33:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 1,233 bytes |
| コンパイル時間 | 927 ms |
| コンパイル使用メモリ | 88,696 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 20:55:32 |
| 合計ジャッジ時間 | 1,854 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;
const int N = 10;
int n;
int a[N], b[N];
bool rec(int m, int *tbl, int k) {
if (k >= n) {
return true;
}
REP(i, 0, m) {
if (tbl[i] >= a[k]) {
tbl[i] -= a[k];
bool res = rec(m, tbl, k + 1);
tbl[i] += a[k];
if (res) {
return 1;
}
}
}
return 0;
}
bool solve(int m) {
return rec(m, b, 0);
}
int main(void){
int m;
cin >> n;
REP(i, 0, n) {
cin >> a[i];
}
cin >> m;
REP(i, 0, m) {
cin >> b[i];
}
sort(b, b + m);
reverse(b, b + m);
REP (i, 1, m + 1) {
if (solve(i)) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}