結果

問題 No.393 2本の竹
ユーザー ckawatakckawatak
提出日時 2019-01-09 23:21:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 361 ms / 1,000 ms
コード長 700 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 80,852 KB
最終ジャッジ日時 2023-08-15 17:00:06
合計ジャッジ時間 4,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,108 KB
testcase_01 AC 81 ms
76,048 KB
testcase_02 AC 85 ms
76,004 KB
testcase_03 AC 86 ms
76,024 KB
testcase_04 AC 81 ms
76,028 KB
testcase_05 AC 83 ms
76,008 KB
testcase_06 AC 78 ms
76,008 KB
testcase_07 AC 85 ms
76,004 KB
testcase_08 AC 96 ms
76,304 KB
testcase_09 AC 361 ms
80,852 KB
testcase_10 AC 124 ms
78,520 KB
testcase_11 AC 161 ms
79,012 KB
testcase_12 AC 181 ms
79,464 KB
testcase_13 AC 129 ms
77,792 KB
testcase_14 AC 97 ms
76,480 KB
testcase_15 AC 87 ms
76,472 KB
testcase_16 AC 96 ms
78,056 KB
testcase_17 AC 82 ms
75,900 KB
testcase_18 AC 82 ms
75,824 KB
testcase_19 AC 79 ms
75,880 KB
testcase_20 AC 79 ms
75,932 KB
testcase_21 AC 83 ms
76,052 KB
testcase_22 AC 211 ms
80,540 KB
testcase_23 AC 121 ms
77,900 KB
testcase_24 AC 87 ms
75,932 KB
testcase_25 AC 84 ms
76,040 KB
testcase_26 AC 80 ms
75,960 KB
testcase_27 AC 321 ms
79,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    acc = 0
    count = 0
    while count < m and acc + fragments[count] <= n1 + n2:
        acc = acc + fragments[count]
        count = count + 1

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

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

    last = n1
    while not dp[last]:
        last = last - 1

    found = (acc - last <= n2)
    print(count - (0 if found else 1))
0