結果

問題 No.393 2本の竹
ユーザー ckawatakckawatak
提出日時 2019-01-09 23:21:44
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 349 ms / 1,000 ms
コード長 700 bytes
コンパイル時間 334 ms
使用メモリ 85,404 KB
最終ジャッジ日時 2022-12-28 22:36:30
合計ジャッジ時間 5,322 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 101 ms
80,948 KB
testcase_01 AC 91 ms
80,584 KB
testcase_02 AC 96 ms
80,400 KB
testcase_03 AC 94 ms
80,436 KB
testcase_04 AC 92 ms
80,468 KB
testcase_05 AC 94 ms
80,376 KB
testcase_06 AC 93 ms
80,556 KB
testcase_07 AC 97 ms
80,660 KB
testcase_08 AC 111 ms
80,876 KB
testcase_09 AC 349 ms
85,404 KB
testcase_10 AC 136 ms
82,780 KB
testcase_11 AC 169 ms
83,512 KB
testcase_12 AC 183 ms
84,032 KB
testcase_13 AC 140 ms
82,016 KB
testcase_14 AC 109 ms
80,928 KB
testcase_15 AC 97 ms
80,772 KB
testcase_16 AC 108 ms
82,764 KB
testcase_17 AC 95 ms
80,876 KB
testcase_18 AC 93 ms
80,616 KB
testcase_19 AC 92 ms
80,688 KB
testcase_20 AC 92 ms
80,768 KB
testcase_21 AC 95 ms
80,496 KB
testcase_22 AC 219 ms
84,900 KB
testcase_23 AC 134 ms
83,068 KB
testcase_24 AC 102 ms
80,864 KB
testcase_25 AC 98 ms
80,828 KB
testcase_26 AC 91 ms
80,412 KB
testcase_27 AC 326 ms
84,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
        
for i in range(N):
    n1, n2 = sorted(list(map(int, input().split(' '))))
    m = int(input())
    fragments = sorted(list(map(int, input().split(' '))))

    acc = 0
    count = 0
    while count < m and acc + fragments[count] <= n1 + n2:
        acc = acc + fragments[count]
        count = count + 1

    dp = [False for _ in range(n1+1)]
    dp[0] = True

    for i in range(count):
        for j in reversed(range(n1)):
            if dp[j]:
                if j + fragments[i] < n1+1:
                    dp[j + fragments[i]] = True

    last = n1
    while not dp[last]:
        last = last - 1

    found = (acc - last <= n2)
    print(count - (0 if found else 1))
0