結果

問題 No.393 2本の竹
ユーザー rlangevin
提出日時 2023-11-22 08:56:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 544 ms / 1,000 ms
コード長 626 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 251,904 KB
最終ジャッジ日時 2024-09-26 07:25:34
合計ジャッジ時間 6,031 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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