結果

問題 No.393 2本の竹
コンテスト
ユーザー roaris
提出日時 2019-12-13 00:24:26
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 690 ms / 1,000 ms
コード長 702 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 117 ms
コンパイル使用メモリ 85,076 KB
実行使用メモリ 263,296 KB
最終ジャッジ日時 2026-03-12 13:17:18
合計ジャッジ時間 5,132 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

d = int(input())

for _ in range(d):
    n1, n2 = map(int, input().split())
    m = int(input())
    A = list(map(int, input().split()))
    A.sort()
    dp = [[False]*(n1+1) for _ in range(m+1)]
    dp[0][0] = True
    acc = 0
    
    for i in range(m):
        for j in range(n1+1):
            if j+A[i]<=n1:
                dp[i+1][j+A[i]] |= dp[i][j]
            
            n2_used = acc-j
            
            if n2_used+A[i]<=n2:
                dp[i+1][j] |= dp[i][j]
            
        acc += A[i]
    
    for i in range(m, -1, -1):
        for j in range(n1+1):
            if dp[i][j]:
                print(i)
                break
        else:
            continue
        break
0