結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
87,044 KB
testcase_01 AC 784 ms
89,460 KB
testcase_02 AC 120 ms
87,192 KB
testcase_03 AC 119 ms
86,868 KB
testcase_04 AC 126 ms
86,856 KB
testcase_05 AC 695 ms
89,080 KB
testcase_06 AC 162 ms
88,844 KB
testcase_07 AC 116 ms
87,040 KB
testcase_08 AC 120 ms
86,940 KB
testcase_09 AC 117 ms
86,936 KB
testcase_10 AC 118 ms
86,912 KB
testcase_11 AC 120 ms
86,656 KB
testcase_12 AC 117 ms
86,784 KB
testcase_13 AC 118 ms
86,656 KB
testcase_14 AC 120 ms
87,168 KB
testcase_15 AC 120 ms
86,928 KB
testcase_16 AC 122 ms
87,168 KB
testcase_17 AC 445 ms
88,960 KB
testcase_18 AC 159 ms
88,832 KB
testcase_19 AC 558 ms
88,920 KB
testcase_20 AC 132 ms
88,448 KB
testcase_21 AC 167 ms
88,628 KB
testcase_22 AC 672 ms
88,860 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 119 ms
86,784 KB
testcase_26 AC 131 ms
88,528 KB
testcase_27 AC 176 ms
88,960 KB
testcase_28 AC 472 ms
88,936 KB
testcase_29 AC 467 ms
88,948 KB
testcase_30 WA -
testcase_31 AC 120 ms
86,716 KB
testcase_32 AC 689 ms
88,980 KB
testcase_33 AC 502 ms
88,956 KB
testcase_34 AC 696 ms
89,088 KB
testcase_35 AC 529 ms
88,960 KB
testcase_36 AC 539 ms
88,704 KB
testcase_37 AC 529 ms
88,832 KB
testcase_38 AC 582 ms
88,516 KB
testcase_39 AC 705 ms
88,972 KB
testcase_40 AC 764 ms
88,896 KB
testcase_41 AC 652 ms
89,384 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