結果
問題 |
No.50 おもちゃ箱
|
ユーザー |
![]() |
提出日時 | 2014-10-27 00:00:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,172 bytes |
コンパイル時間 | 883 ms |
コンパイル使用メモリ | 68,864 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 13:42:18 |
合計ジャッジ時間 | 2,364 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 WA * 9 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <functional> #include <cstring> using namespace std; #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).begin(), (x).end(), greater<int>() ) #define CLEAR(d) memset((d), 0, (sizeof((d)))) int main() { int n, m, ans = 0, g = 0; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } cin >> m; vector<int> b(m); for (int i = 0; i < m; i++) { cin >> b[i]; } RSORT(a); RSORT(b); int t[10]; CLEAR(t); for (ans = 0; ans < m; ans++) { int sum = b[ans]; for (int i = 0; i < n; i++) { if (t[i] == 0 && sum >= a[i]) { sum -= a[i]; t[i] = 1; } } int flag = 0; for (int i = 0; i < n; i++) { if (t[i] == 0) { flag = 1; break; } } if (flag == 0) { g = 1; break; } } if (g == 0) ans = -2; printf("%d\n", ans+1); return 0; }