結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
86,656 KB
testcase_01 AC 844 ms
89,088 KB
testcase_02 AC 143 ms
86,912 KB
testcase_03 AC 141 ms
86,656 KB
testcase_04 AC 140 ms
86,784 KB
testcase_05 AC 722 ms
88,960 KB
testcase_06 RE -
testcase_07 AC 142 ms
86,912 KB
testcase_08 AC 142 ms
86,912 KB
testcase_09 AC 141 ms
86,912 KB
testcase_10 WA -
testcase_11 AC 141 ms
86,656 KB
testcase_12 WA -
testcase_13 AC 141 ms
86,784 KB
testcase_14 AC 144 ms
87,168 KB
testcase_15 AC 141 ms
86,784 KB
testcase_16 AC 146 ms
87,168 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 587 ms
88,704 KB
testcase_20 AC 152 ms
88,704 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 142 ms
86,784 KB
testcase_25 AC 141 ms
86,784 KB
testcase_26 AC 153 ms
88,832 KB
testcase_27 AC 199 ms
88,960 KB
testcase_28 AC 509 ms
88,960 KB
testcase_29 AC 502 ms
88,832 KB
testcase_30 WA -
testcase_31 AC 143 ms
86,784 KB
testcase_32 AC 722 ms
88,960 KB
testcase_33 AC 521 ms
88,960 KB
testcase_34 AC 733 ms
88,832 KB
testcase_35 AC 564 ms
88,448 KB
testcase_36 AC 577 ms
88,832 KB
testcase_37 AC 569 ms
88,704 KB
testcase_38 AC 617 ms
88,832 KB
testcase_39 AC 746 ms
88,448 KB
testcase_40 AC 810 ms
88,960 KB
testcase_41 AC 674 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 = """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 == N-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