結果

問題 No.527 ナップサック容量問題
コンテスト
ユーザー takakin
提出日時 2020-06-01 23:18:24
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 473 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 139 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 64,256 KB
最終ジャッジ日時 2026-05-16 16:20:33
合計ジャッジ時間 3,236 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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