結果

問題 No.50 おもちゃ箱
ユーザー tcltktcltk
提出日時 2021-05-19 23:49:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 804 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 89,128 KB
最終ジャッジ日時 2024-10-10 05:45:47
合計ジャッジ時間 15,434 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
87,168 KB
testcase_01 AC 804 ms
89,088 KB
testcase_02 AC 131 ms
86,724 KB
testcase_03 AC 125 ms
86,868 KB
testcase_04 AC 123 ms
86,912 KB
testcase_05 AC 704 ms
88,876 KB
testcase_06 AC 172 ms
88,768 KB
testcase_07 AC 124 ms
86,912 KB
testcase_08 AC 123 ms
87,040 KB
testcase_09 AC 124 ms
86,992 KB
testcase_10 AC 124 ms
86,656 KB
testcase_11 AC 126 ms
86,532 KB
testcase_12 AC 124 ms
86,544 KB
testcase_13 AC 132 ms
87,016 KB
testcase_14 AC 129 ms
86,784 KB
testcase_15 AC 124 ms
86,912 KB
testcase_16 AC 130 ms
87,212 KB
testcase_17 AC 443 ms
88,812 KB
testcase_18 AC 164 ms
88,960 KB
testcase_19 AC 567 ms
88,960 KB
testcase_20 AC 138 ms
88,448 KB
testcase_21 AC 182 ms
88,704 KB
testcase_22 AC 507 ms
88,832 KB
testcase_23 AC 152 ms
88,704 KB
testcase_24 AC 128 ms
86,784 KB
testcase_25 AC 125 ms
87,040 KB
testcase_26 AC 137 ms
88,512 KB
testcase_27 AC 182 ms
88,580 KB
testcase_28 AC 515 ms
89,128 KB
testcase_29 AC 513 ms
88,780 KB
testcase_30 AC 438 ms
88,832 KB
testcase_31 AC 125 ms
86,528 KB
testcase_32 AC 676 ms
88,904 KB
testcase_33 AC 522 ms
88,960 KB
testcase_34 AC 705 ms
88,704 KB
testcase_35 AC 537 ms
88,704 KB
testcase_36 AC 556 ms
88,696 KB
testcase_37 AC 527 ms
88,896 KB
testcase_38 AC 568 ms
88,960 KB
testcase_39 AC 713 ms
88,960 KB
testcase_40 AC 778 ms
88,908 KB
testcase_41 AC 651 ms
88,832 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