結果

問題 No.393 2本の竹
ユーザー roarisroaris
提出日時 2019-12-13 00:49:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 990 ms / 1,000 ms
コード長 767 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 85,872 KB
最終ジャッジ日時 2023-09-08 08:39:49
合計ジャッジ時間 8,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
76,852 KB
testcase_01 AC 92 ms
76,100 KB
testcase_02 AC 106 ms
76,940 KB
testcase_03 AC 100 ms
76,848 KB
testcase_04 AC 89 ms
76,184 KB
testcase_05 AC 97 ms
76,800 KB
testcase_06 AC 92 ms
76,248 KB
testcase_07 AC 112 ms
76,908 KB
testcase_08 AC 135 ms
77,476 KB
testcase_09 AC 990 ms
85,872 KB
testcase_10 AC 359 ms
84,984 KB
testcase_11 AC 433 ms
83,356 KB
testcase_12 AC 491 ms
84,248 KB
testcase_13 AC 309 ms
81,324 KB
testcase_14 AC 229 ms
79,848 KB
testcase_15 AC 129 ms
77,844 KB
testcase_16 AC 206 ms
81,324 KB
testcase_17 AC 100 ms
76,248 KB
testcase_18 AC 96 ms
76,832 KB
testcase_19 AC 88 ms
76,072 KB
testcase_20 AC 95 ms
76,216 KB
testcase_21 AC 100 ms
76,816 KB
testcase_22 AC 560 ms
85,320 KB
testcase_23 AC 305 ms
80,372 KB
testcase_24 AC 119 ms
77,048 KB
testcase_25 AC 113 ms
77,084 KB
testcase_26 AC 87 ms
76,176 KB
testcase_27 AC 958 ms
84,888 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):
        now = i&1
        nxt = (i+1)&1
        
        for j in range(n1+1):
            dp[nxt][j] = False
            
        for j in range(n1+1):
            if j+A[i]<=n1:
                dp[nxt][j+A[i]] |= dp[now][j]
            
            n2_used = acc-j
            
            if n2_used+A[i]<=n2:
                dp[nxt][j] |= dp[now][j]
            
        if True in dp[nxt]:
            ans = i+1
        else:
            break
            
        acc += A[i]
    
    print(ans)
0