結果

問題 No.50 おもちゃ箱
ユーザー tcltktcltk
提出日時 2021-05-19 23:48:07
言語 PyPy3
(7.3.13)
結果
RE  
実行時間 -
コード長 1,026 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 83,464 KB
最終ジャッジ日時 2023-07-31 12:12:26
合計ジャッジ時間 20,340 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
83,096 KB
testcase_01 AC 925 ms
83,128 KB
testcase_02 AC 214 ms
82,872 KB
testcase_03 AC 203 ms
80,860 KB
testcase_04 AC 203 ms
80,608 KB
testcase_05 AC 825 ms
83,132 KB
testcase_06 AC 249 ms
82,940 KB
testcase_07 AC 201 ms
80,852 KB
testcase_08 AC 203 ms
80,912 KB
testcase_09 AC 202 ms
80,904 KB
testcase_10 AC 200 ms
80,792 KB
testcase_11 AC 202 ms
80,576 KB
testcase_12 AC 203 ms
80,844 KB
testcase_13 AC 201 ms
80,588 KB
testcase_14 AC 213 ms
83,016 KB
testcase_15 AC 207 ms
80,776 KB
testcase_16 AC 216 ms
83,124 KB
testcase_17 AC 558 ms
83,320 KB
testcase_18 AC 247 ms
83,036 KB
testcase_19 AC 670 ms
83,196 KB
testcase_20 AC 213 ms
83,116 KB
testcase_21 AC 253 ms
83,248 KB
testcase_22 AC 785 ms
83,464 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 198 ms
80,912 KB
testcase_26 AC 213 ms
83,140 KB
testcase_27 AC 262 ms
83,124 KB
testcase_28 AC 595 ms
83,368 KB
testcase_29 AC 595 ms
82,884 KB
testcase_30 WA -
testcase_31 AC 201 ms
80,920 KB
testcase_32 AC 810 ms
83,220 KB
testcase_33 AC 602 ms
83,392 KB
testcase_34 AC 826 ms
83,164 KB
testcase_35 AC 644 ms
83,116 KB
testcase_36 AC 656 ms
83,112 KB
testcase_37 AC 644 ms
83,444 KB
testcase_38 AC 693 ms
83,052 KB
testcase_39 AC 844 ms
83,364 KB
testcase_40 AC 898 ms
83,232 KB
testcase_41 AC 763 ms
83,444 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