結果

問題 No.393 2本の竹
ユーザー ckawatakckawatak
提出日時 2019-01-09 23:23:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 351 ms / 1,000 ms
コード長 867 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 80,772 KB
最終ジャッジ日時 2023-08-15 17:00:16
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,336 KB
testcase_01 AC 80 ms
75,576 KB
testcase_02 AC 84 ms
75,596 KB
testcase_03 AC 86 ms
75,444 KB
testcase_04 AC 79 ms
75,452 KB
testcase_05 AC 79 ms
75,472 KB
testcase_06 AC 75 ms
75,520 KB
testcase_07 AC 81 ms
75,468 KB
testcase_08 AC 84 ms
76,024 KB
testcase_09 AC 351 ms
80,772 KB
testcase_10 AC 117 ms
77,928 KB
testcase_11 AC 152 ms
78,320 KB
testcase_12 AC 174 ms
78,788 KB
testcase_13 AC 123 ms
77,364 KB
testcase_14 AC 91 ms
76,004 KB
testcase_15 AC 82 ms
75,912 KB
testcase_16 AC 92 ms
77,340 KB
testcase_17 AC 79 ms
75,584 KB
testcase_18 AC 80 ms
75,356 KB
testcase_19 AC 76 ms
75,328 KB
testcase_20 AC 78 ms
75,436 KB
testcase_21 AC 80 ms
75,396 KB
testcase_22 AC 199 ms
79,904 KB
testcase_23 AC 114 ms
77,212 KB
testcase_24 AC 82 ms
75,436 KB
testcase_25 AC 82 ms
75,372 KB
testcase_26 AC 79 ms
75,432 KB
testcase_27 AC 309 ms
79,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX = 100000

def accept(n1, n2, fragments, upper):
    if upper == 0:
        return True

    total = 0
    for i in range(upper):
        total = total + fragments[i]
    if n1+n2 < total:
        return False

    dp = [False for _ in range(n1+1)]
    dp[0] = True

    for i in range(upper):
        for j in reversed(range(n1+1)):
            if dp[j]:
                if j + fragments[i] <= n1:
                    dp[j + fragments[i]] = True

    for i in reversed(range(n1+1)):
        if dp[i] and total - i <= n2:
            return True

    return False

N = int(input())
        
for i in range(N):
    n1, n2 = sorted(list(map(int, input().split(' '))))
    m = int(input())
    fragments = sorted(list(map(int, input().split(' '))))

    for j in reversed(range(0,m+1)):
        if accept(n1, n2, fragments, j):
            print(j)
            break
0