結果
| 問題 | No.50 おもちゃ箱 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-02-23 17:15:14 | 
| 言語 | PyPy2 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,141 ms / 5,000 ms | 
| コード長 | 425 bytes | 
| コンパイル時間 | 1,437 ms | 
| コンパイル使用メモリ | 76,316 KB | 
| 実行使用メモリ | 78,336 KB | 
| 最終ジャッジ日時 | 2024-06-25 20:55:26 | 
| 合計ジャッジ時間 | 19,552 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 38 | 
ソースコード
import itertools as it
N = int(raw_input())
A = map(int,raw_input().split())
M = int(raw_input())
_B = sorted(map(int,raw_input().split()),reverse = True)
ans = M+1
for order in it.permutations(A,N):
    B = _B[:]
    i = j = 0
    while i < N and j < M:
        if B[j] >= order[i]:
            B[j] -= order[i]
            i += 1
        else:
            j += 1
    ans = min(ans, j+1)
print ans if ans < M+1 else -1
    
            
            
            
        