結果

問題 No.527 ナップサック容量問題
ユーザー nanaenanae
提出日時 2017-06-09 22:37:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 62,300 KB
最終ジャッジ日時 2023-10-23 22:08:12
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,104 KB
testcase_01 AC 41 ms
60,104 KB
testcase_02 AC 38 ms
60,028 KB
testcase_03 AC 42 ms
60,248 KB
testcase_04 AC 39 ms
60,104 KB
testcase_05 AC 57 ms
60,248 KB
testcase_06 AC 80 ms
62,296 KB
testcase_07 AC 74 ms
62,300 KB
testcase_08 AC 56 ms
60,248 KB
testcase_09 AC 38 ms
60,028 KB
testcase_10 AC 83 ms
62,300 KB
testcase_11 AC 68 ms
60,248 KB
testcase_12 AC 60 ms
60,248 KB
testcase_13 AC 82 ms
62,296 KB
testcase_14 AC 57 ms
62,300 KB
testcase_15 AC 64 ms
62,300 KB
testcase_16 AC 43 ms
60,108 KB
testcase_17 AC 59 ms
62,300 KB
testcase_18 AC 62 ms
62,300 KB
testcase_19 AC 43 ms
60,248 KB
testcase_20 AC 54 ms
60,248 KB
testcase_21 AC 89 ms
62,296 KB
testcase_22 AC 71 ms
60,248 KB
testcase_23 AC 86 ms
62,296 KB
testcase_24 AC 49 ms
60,248 KB
testcase_25 AC 70 ms
60,248 KB
testcase_26 AC 67 ms
60,248 KB
testcase_27 AC 68 ms
60,248 KB
testcase_28 AC 64 ms
60,248 KB
testcase_29 AC 87 ms
62,296 KB
testcase_30 AC 43 ms
60,028 KB
testcase_31 AC 58 ms
60,248 KB
testcase_32 AC 62 ms
60,248 KB
testcase_33 AC 58 ms
60,248 KB
testcase_34 AC 63 ms
60,248 KB
testcase_35 AC 66 ms
62,300 KB
testcase_36 AC 41 ms
60,108 KB
testcase_37 AC 64 ms
62,300 KB
testcase_38 AC 70 ms
62,300 KB
testcase_39 AC 67 ms
62,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

lim = 10**5

def solve():
    n = int(input())

    v = [0] * n
    w = [0] * n

    for i in range(n):
        vi, wi = map(int, input().split())
        v[i] = vi
        w[i] = wi

    V = int(input())

    dp = [0] * (lim + 1)

    for i in range(n):
        for j in range(lim, w[i] - 1, -1):
            dp[j] = max(dp[j], dp[j - w[i]] + v[i])

    min_a = lim + 1
    max_a = 0

    for i in range(lim + 1):
        if dp[i] == V:
            min_a = i
            break

    for i in range(lim, -1, -1):
        if dp[i] == V:
            max_a = i
            break

    print(min_a if min_a > 0 else 1)

    if sum(v) == V:
        print('inf')
    else:
        print(max_a)


if __name__ == '__main__':
    solve()
0