結果

問題 No.393 2本の竹
ユーザー rlangevinrlangevin
提出日時 2023-11-22 08:56:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 520 ms / 1,000 ms
コード長 626 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 251,664 KB
最終ジャッジ日時 2023-11-22 08:56:54
合計ジャッジ時間 6,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
68,332 KB
testcase_01 AC 53 ms
64,188 KB
testcase_02 AC 68 ms
68,352 KB
testcase_03 AC 54 ms
66,252 KB
testcase_04 AC 49 ms
64,188 KB
testcase_05 AC 54 ms
64,184 KB
testcase_06 AC 52 ms
64,176 KB
testcase_07 AC 66 ms
70,812 KB
testcase_08 AC 80 ms
75,968 KB
testcase_09 AC 520 ms
202,876 KB
testcase_10 AC 278 ms
137,792 KB
testcase_11 AC 261 ms
144,556 KB
testcase_12 AC 299 ms
162,792 KB
testcase_13 AC 232 ms
129,356 KB
testcase_14 AC 164 ms
111,224 KB
testcase_15 AC 135 ms
96,308 KB
testcase_16 AC 207 ms
143,764 KB
testcase_17 AC 57 ms
66,248 KB
testcase_18 AC 53 ms
64,160 KB
testcase_19 AC 52 ms
64,192 KB
testcase_20 AC 58 ms
64,188 KB
testcase_21 AC 58 ms
66,252 KB
testcase_22 AC 343 ms
177,204 KB
testcase_23 AC 216 ms
130,448 KB
testcase_24 AC 84 ms
75,716 KB
testcase_25 AC 70 ms
72,500 KB
testcase_26 AC 54 ms
64,176 KB
testcase_27 AC 468 ms
251,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

t = int(input())
inf = 10 ** 18
for _ in range(t):
    n1, n2 = map(int, input().split())
    m = int(input())
    A = sorted(list(map(int, input().split())))
    pre = [-inf] * (n1 + 1)
    pre[0] = 0
    now = 0
    ans = -1
    for a in A:
        dp = [-inf] * (n1 + 1)
        for i in range(n1 + 1):
            if i + a <= n1:
                dp[i + a] = max(dp[i + a], pre[i] + 1)
            if now - i + a <= n2:
                dp[i] = max(dp[i], pre[i] + 1)
        ans = max(ans, max(dp))
        now += a
        dp, pre = pre, dp

    print(ans) if ans != -1 else print(0)
0