結果

問題 No.50 おもちゃ箱
ユーザー tcltktcltk
提出日時 2021-05-19 23:49:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 716 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 89,184 KB
最終ジャッジ日時 2024-04-18 12:33:48
合計ジャッジ時間 14,220 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
87,128 KB
testcase_01 AC 716 ms
88,720 KB
testcase_02 AC 115 ms
86,992 KB
testcase_03 AC 119 ms
86,788 KB
testcase_04 AC 119 ms
86,596 KB
testcase_05 AC 642 ms
88,876 KB
testcase_06 AC 160 ms
88,732 KB
testcase_07 AC 118 ms
86,448 KB
testcase_08 AC 108 ms
86,964 KB
testcase_09 AC 112 ms
86,960 KB
testcase_10 AC 113 ms
86,832 KB
testcase_11 AC 118 ms
87,132 KB
testcase_12 AC 114 ms
86,592 KB
testcase_13 AC 117 ms
87,040 KB
testcase_14 AC 119 ms
86,780 KB
testcase_15 AC 118 ms
86,920 KB
testcase_16 AC 116 ms
87,188 KB
testcase_17 AC 401 ms
88,520 KB
testcase_18 AC 154 ms
88,784 KB
testcase_19 AC 532 ms
88,868 KB
testcase_20 AC 129 ms
88,772 KB
testcase_21 AC 161 ms
88,828 KB
testcase_22 AC 468 ms
88,580 KB
testcase_23 AC 145 ms
88,872 KB
testcase_24 AC 110 ms
86,856 KB
testcase_25 AC 119 ms
87,012 KB
testcase_26 AC 128 ms
89,184 KB
testcase_27 AC 167 ms
88,860 KB
testcase_28 AC 478 ms
88,524 KB
testcase_29 AC 463 ms
88,512 KB
testcase_30 AC 409 ms
88,748 KB
testcase_31 AC 119 ms
86,796 KB
testcase_32 AC 606 ms
89,032 KB
testcase_33 AC 473 ms
88,852 KB
testcase_34 AC 644 ms
88,972 KB
testcase_35 AC 483 ms
88,832 KB
testcase_36 AC 501 ms
88,648 KB
testcase_37 AC 473 ms
88,596 KB
testcase_38 AC 512 ms
88,936 KB
testcase_39 AC 661 ms
88,864 KB
testcase_40 AC 706 ms
88,660 KB
testcase_41 AC 599 ms
88,912 KB
権限があれば一括ダウンロードができます

ソースコード

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 = """9
# 10 18 19 12 8 12 1 1 4
# 1
# 1
# """
# 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 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