結果

問題 No.527 ナップサック容量問題
ユーザー takakintakakin
提出日時 2020-06-01 23:18:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 63,616 KB
最終ジャッジ日時 2024-05-02 04:19:07
合計ジャッジ時間 4,649 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
59,648 KB
testcase_01 AC 55 ms
60,800 KB
testcase_02 AC 54 ms
60,160 KB
testcase_03 AC 59 ms
62,208 KB
testcase_04 AC 49 ms
58,752 KB
testcase_05 AC 77 ms
62,080 KB
testcase_06 AC 101 ms
62,592 KB
testcase_07 AC 93 ms
62,592 KB
testcase_08 AC 77 ms
62,848 KB
testcase_09 AC 49 ms
58,880 KB
testcase_10 AC 102 ms
62,720 KB
testcase_11 AC 88 ms
62,848 KB
testcase_12 AC 80 ms
62,336 KB
testcase_13 AC 104 ms
62,976 KB
testcase_14 AC 73 ms
62,336 KB
testcase_15 AC 82 ms
62,336 KB
testcase_16 AC 56 ms
61,312 KB
testcase_17 AC 78 ms
62,720 KB
testcase_18 AC 81 ms
62,208 KB
testcase_19 AC 62 ms
62,848 KB
testcase_20 AC 73 ms
61,568 KB
testcase_21 AC 109 ms
62,080 KB
testcase_22 AC 91 ms
61,824 KB
testcase_23 AC 106 ms
62,464 KB
testcase_24 AC 67 ms
62,080 KB
testcase_25 AC 88 ms
61,696 KB
testcase_26 AC 86 ms
61,952 KB
testcase_27 AC 87 ms
62,464 KB
testcase_28 AC 82 ms
62,080 KB
testcase_29 AC 108 ms
62,720 KB
testcase_30 AC 56 ms
60,160 KB
testcase_31 AC 73 ms
60,928 KB
testcase_32 AC 79 ms
61,056 KB
testcase_33 AC 74 ms
61,184 KB
testcase_34 AC 79 ms
60,800 KB
testcase_35 AC 86 ms
62,336 KB
testcase_36 AC 60 ms
61,824 KB
testcase_37 AC 80 ms
63,616 KB
testcase_38 AC 84 ms
62,080 KB
testcase_39 AC 82 ms
61,824 KB
権限があれば一括ダウンロードができます

ソースコード

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