結果

問題 No.527 ナップサック容量問題
ユーザー takakintakakin
提出日時 2020-06-01 23:18:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 473 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-05-02 04:18:36
合計ジャッジ時間 7,686 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 226 ms
17,152 KB
testcase_01 AC 299 ms
14,464 KB
testcase_02 AC 171 ms
11,392 KB
testcase_03 AC 302 ms
14,464 KB
testcase_04 AC 110 ms
11,392 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
VW=[tuple(map(int,input().split())) for _ in range(n)]
vmax=int(input())
DP=[0]*100001
for i in range(n):
  v,w=VW[i]
  for j in range(100001)[::-1]:
    if j<w:
      DP[j]=DP[j]
    else:
      DP[j]=max(DP[j],DP[j-w]+v)
ans1,ans2=-1,-1
for i in range(1,100001):
  if DP[i]==vmax:
    if ans1==-1:
      ans1=i
    ans2=i
if ans2==100000:
  print(ans1,"inf",sep="\n")
else:
  print(ans1,ans2,sep="\n")
0