結果
| 問題 | No.50 おもちゃ箱 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-05-19 23:48:07 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,026 bytes | 
| コンパイル時間 | 317 ms | 
| コンパイル使用メモリ | 82,312 KB | 
| 実行使用メモリ | 89,076 KB | 
| 最終ジャッジ日時 | 2024-10-10 05:42:57 | 
| 合計ジャッジ時間 | 15,722 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 35 WA * 1 RE * 2 | 
ソースコード
#region Header
#!/usr/bin/env python3
# from typing import *
import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq
def input():
    return sys.stdin.readline()[:-1]
# sys.setrecursionlimit(1000000)
#endregion
# _INPUT = """2
# 8 12
# 2
# 10 10
# """
# sys.stdin = io.StringIO(_INPUT)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = int(input())
    B = list(map(int, input().split()))
    B.sort(reverse=True)
    ans = 100
    for pat in itertools.permutations(A):
        i = 0
        cap = B[0]
        ok = True
        for item in pat:
            if item <= cap:
                cap -= item
            else:
                i += 1
                if i == M-1 or B[i] < item:
                    ok = False
                    break
                cap = B[i] - item
        if ok:
            ans = min(ans, i+1)
    if ans == 100:
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()
            
            
            
        