結果

問題 No.50 おもちゃ箱
ユーザー tcltk
提出日時 2021-05-19 23:47:21
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,026 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 89,216 KB
最終ジャッジ日時 2024-10-10 05:42:16
合計ジャッジ時間 16,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 30 WA * 3 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 == N-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()
0