結果

問題 No.50 おもちゃ箱
ユーザー tcltktcltk
提出日時 2021-05-19 23:48:07
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,026 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 89,216 KB
最終ジャッジ日時 2024-04-18 12:30:48
合計ジャッジ時間 15,281 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
87,168 KB
testcase_01 AC 784 ms
88,828 KB
testcase_02 AC 121 ms
87,156 KB
testcase_03 AC 114 ms
86,928 KB
testcase_04 AC 120 ms
87,040 KB
testcase_05 AC 687 ms
88,992 KB
testcase_06 AC 172 ms
89,088 KB
testcase_07 AC 119 ms
86,480 KB
testcase_08 AC 117 ms
86,912 KB
testcase_09 AC 118 ms
86,908 KB
testcase_10 AC 119 ms
86,912 KB
testcase_11 AC 122 ms
86,980 KB
testcase_12 AC 119 ms
86,912 KB
testcase_13 AC 121 ms
86,464 KB
testcase_14 AC 124 ms
87,008 KB
testcase_15 AC 120 ms
86,540 KB
testcase_16 AC 125 ms
87,072 KB
testcase_17 AC 441 ms
88,704 KB
testcase_18 AC 157 ms
88,892 KB
testcase_19 AC 598 ms
88,960 KB
testcase_20 AC 127 ms
88,524 KB
testcase_21 AC 165 ms
88,704 KB
testcase_22 AC 669 ms
88,660 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 119 ms
86,536 KB
testcase_26 AC 129 ms
88,964 KB
testcase_27 AC 174 ms
88,704 KB
testcase_28 AC 473 ms
89,060 KB
testcase_29 AC 461 ms
88,948 KB
testcase_30 WA -
testcase_31 AC 120 ms
86,716 KB
testcase_32 AC 676 ms
89,216 KB
testcase_33 AC 476 ms
89,116 KB
testcase_34 AC 684 ms
88,960 KB
testcase_35 AC 532 ms
88,700 KB
testcase_36 AC 538 ms
88,584 KB
testcase_37 AC 529 ms
88,580 KB
testcase_38 AC 575 ms
88,648 KB
testcase_39 AC 695 ms
89,088 KB
testcase_40 AC 763 ms
88,704 KB
testcase_41 AC 643 ms
89,108 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 = """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()
0