結果

問題 No.393 2本の竹
ユーザー roarisroaris
提出日時 2019-12-13 00:47:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 938 ms / 1,000 ms
コード長 734 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 86,336 KB
最終ジャッジ日時 2023-09-08 08:38:40
合計ジャッジ時間 8,432 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
76,956 KB
testcase_01 AC 93 ms
76,536 KB
testcase_02 AC 110 ms
77,044 KB
testcase_03 AC 100 ms
76,848 KB
testcase_04 AC 88 ms
76,384 KB
testcase_05 AC 99 ms
76,816 KB
testcase_06 AC 91 ms
76,212 KB
testcase_07 AC 114 ms
77,304 KB
testcase_08 AC 139 ms
77,800 KB
testcase_09 AC 938 ms
86,336 KB
testcase_10 AC 347 ms
85,288 KB
testcase_11 AC 424 ms
83,488 KB
testcase_12 AC 470 ms
84,004 KB
testcase_13 AC 297 ms
81,724 KB
testcase_14 AC 228 ms
79,824 KB
testcase_15 AC 132 ms
77,844 KB
testcase_16 AC 207 ms
81,208 KB
testcase_17 AC 101 ms
77,008 KB
testcase_18 AC 99 ms
76,804 KB
testcase_19 AC 88 ms
76,164 KB
testcase_20 AC 94 ms
76,428 KB
testcase_21 AC 102 ms
76,852 KB
testcase_22 AC 578 ms
85,264 KB
testcase_23 AC 309 ms
80,648 KB
testcase_24 AC 120 ms
77,336 KB
testcase_25 AC 114 ms
76,916 KB
testcase_26 AC 88 ms
76,260 KB
testcase_27 AC 907 ms
84,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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(2)]
    dp[0][0] = True
    acc = 0
    ans = 0
    
    for i in range(m):
        for j in range(n1+1):
            dp[(i+1)&1][j] = False
            
        for j in range(n1+1):
            if j+A[i]<=n1:
                dp[(i+1)&1][j+A[i]] |= dp[i&1][j]
            
            n2_used = acc-j
            
            if n2_used+A[i]<=n2:
                dp[(i+1)&1][j] |= dp[i&1][j]
            
        if True in dp[(i+1)&1]:
            ans = i+1
        else:
            break
            
        acc += A[i]
    
    print(ans)
0