結果

問題 No.50 おもちゃ箱
ユーザー tcltktcltk
提出日時 2021-05-19 23:49:57
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 875 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 83,536 KB
最終ジャッジ日時 2023-07-31 12:13:45
合計ジャッジ時間 19,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 194 ms
83,348 KB
testcase_01 AC 875 ms
83,480 KB
testcase_02 AC 192 ms
83,120 KB
testcase_03 AC 185 ms
80,992 KB
testcase_04 AC 190 ms
80,868 KB
testcase_05 AC 787 ms
83,384 KB
testcase_06 AC 236 ms
83,312 KB
testcase_07 AC 192 ms
80,624 KB
testcase_08 AC 188 ms
80,936 KB
testcase_09 AC 189 ms
80,944 KB
testcase_10 AC 193 ms
80,676 KB
testcase_11 AC 194 ms
81,012 KB
testcase_12 AC 191 ms
80,956 KB
testcase_13 AC 192 ms
80,904 KB
testcase_14 AC 198 ms
82,916 KB
testcase_15 AC 191 ms
80,944 KB
testcase_16 AC 209 ms
82,856 KB
testcase_17 AC 520 ms
83,088 KB
testcase_18 AC 229 ms
83,180 KB
testcase_19 AC 628 ms
83,168 KB
testcase_20 AC 198 ms
83,036 KB
testcase_21 AC 238 ms
83,324 KB
testcase_22 AC 575 ms
83,080 KB
testcase_23 AC 219 ms
83,384 KB
testcase_24 AC 192 ms
80,908 KB
testcase_25 AC 192 ms
80,936 KB
testcase_26 AC 203 ms
83,256 KB
testcase_27 AC 256 ms
83,096 KB
testcase_28 AC 562 ms
83,396 KB
testcase_29 AC 563 ms
82,876 KB
testcase_30 AC 516 ms
82,852 KB
testcase_31 AC 196 ms
80,752 KB
testcase_32 AC 783 ms
83,536 KB
testcase_33 AC 586 ms
83,360 KB
testcase_34 AC 786 ms
83,264 KB
testcase_35 AC 609 ms
83,020 KB
testcase_36 AC 622 ms
83,116 KB
testcase_37 AC 610 ms
83,444 KB
testcase_38 AC 652 ms
83,296 KB
testcase_39 AC 806 ms
83,172 KB
testcase_40 AC 863 ms
83,464 KB
testcase_41 AC 742 ms
83,480 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