結果

問題 No.527 ナップサック容量問題
ユーザー 👑 KazunKazun
提出日時 2021-03-18 02:06:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 357 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 71,424 KB
最終ジャッジ日時 2024-04-27 16:35:14
合計ジャッジ時間 4,266 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
60,544 KB
testcase_01 AC 46 ms
60,416 KB
testcase_02 AC 47 ms
60,800 KB
testcase_03 AC 51 ms
62,208 KB
testcase_04 AC 39 ms
52,912 KB
testcase_05 AC 75 ms
68,064 KB
testcase_06 AC 121 ms
70,912 KB
testcase_07 AC 95 ms
65,536 KB
testcase_08 AC 68 ms
67,968 KB
testcase_09 AC 42 ms
57,728 KB
testcase_10 AC 110 ms
67,072 KB
testcase_11 AC 90 ms
70,016 KB
testcase_12 AC 74 ms
68,608 KB
testcase_13 AC 122 ms
71,424 KB
testcase_14 AC 65 ms
64,896 KB
testcase_15 AC 83 ms
66,048 KB
testcase_16 AC 50 ms
60,672 KB
testcase_17 AC 71 ms
66,304 KB
testcase_18 AC 76 ms
65,408 KB
testcase_19 AC 49 ms
62,208 KB
testcase_20 AC 67 ms
65,920 KB
testcase_21 AC 130 ms
66,924 KB
testcase_22 AC 91 ms
66,048 KB
testcase_23 AC 122 ms
67,072 KB
testcase_24 AC 58 ms
64,640 KB
testcase_25 AC 91 ms
65,920 KB
testcase_26 AC 86 ms
67,008 KB
testcase_27 AC 84 ms
66,048 KB
testcase_28 AC 76 ms
66,304 KB
testcase_29 AC 123 ms
66,688 KB
testcase_30 AC 48 ms
61,696 KB
testcase_31 AC 61 ms
63,360 KB
testcase_32 AC 67 ms
63,488 KB
testcase_33 AC 60 ms
63,360 KB
testcase_34 AC 67 ms
63,872 KB
testcase_35 AC 83 ms
67,200 KB
testcase_36 AC 48 ms
61,184 KB
testcase_37 AC 76 ms
66,432 KB
testcase_38 AC 79 ms
66,452 KB
testcase_39 AC 78 ms
66,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

inf=float("inf")
DP=[-inf]*(1000*N+1)
DP[0]=0

for _ in range(N):
    v,w=map(int,input().split())
    for x in range(1000*N,w-1,-1):
        DP[x]=max(DP[x],DP[x-w]+v)

for x in range(1,1000*N+1):
    DP[x]=max(DP[x],DP[x-1])

V=int(input())
T=[x for x in range(1,1000*N+1) if DP[x]==V]

print(min(T))
print(max(T) if max(DP)!=V else "inf")
0