結果

問題 No.393 2本の竹
ユーザー rlangevinrlangevin
提出日時 2023-11-22 12:24:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 747 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 84,696 KB
最終ジャッジ日時 2023-11-22 12:24:44
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
62,100 KB
testcase_01 AC 45 ms
59,504 KB
testcase_02 AC 52 ms
62,112 KB
testcase_03 AC 47 ms
62,116 KB
testcase_04 AC 48 ms
59,768 KB
testcase_05 WA -
testcase_06 AC 43 ms
59,384 KB
testcase_07 AC 49 ms
62,108 KB
testcase_08 AC 56 ms
64,188 KB
testcase_09 AC 449 ms
79,528 KB
testcase_10 AC 214 ms
73,804 KB
testcase_11 AC 202 ms
73,300 KB
testcase_12 AC 324 ms
74,224 KB
testcase_13 AC 206 ms
68,508 KB
testcase_14 AC 93 ms
65,392 KB
testcase_15 AC 63 ms
60,756 KB
testcase_16 AC 130 ms
65,220 KB
testcase_17 AC 48 ms
62,116 KB
testcase_18 AC 48 ms
62,100 KB
testcase_19 AC 44 ms
59,504 KB
testcase_20 AC 47 ms
62,108 KB
testcase_21 AC 51 ms
62,108 KB
testcase_22 AC 465 ms
80,480 KB
testcase_23 AC 156 ms
68,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 531 ms
84,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def check(m, A, n1, n2):
    s = sum(A[:m])
    if s > n1 + n2:
        return False
    dp = [0] * (n1 + 1)
    dp[0] = 1
    for a in A:
        for i in range(n1, -1, -1):
            if i + a > n1:
                continue
            dp[i + a] |= dp[i]
    for i in range(n1 + 1):
        if dp[i] and s - i <= n2:
            return True
    return False


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())))

    yes = 0
    no = m + 1
    while no - yes != 1:
        mid = (yes + no)//2
        if check(mid, A, n1, n2):
            yes = mid
        else:
            no = mid
    print(yes)
0