結果

問題 No.3401 Large Knapsack Problem
コンテスト
ユーザー titia
提出日時 2025-12-08 02:06:35
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 793 ms / 2,000 ms
+ 895µs
コード長 431 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 409 ms
コンパイル使用メモリ 95,980 KB
実行使用メモリ 161,536 KB
最終ジャッジ日時 2026-07-19 06:36:12
合計ジャッジ時間 24,664 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

N,W=map(int,input().split())

VW=[list(map(int,input().split())) for i in range(N)]

VW.sort(key=lambda x:x[0]/x[1],reverse=True)

DP=[0]*(10**7+1)

for v,w in VW:
    for i in range(10**7+1):
        if i+w<=10**7:
            DP[i+w]=max(DP[i+w],DP[i]+v)

if W<=10**7:
    print(DP[W])
else:
    v0,w0=VW[0]
    
    k=(W-10**7)//w0
    W1=W-(k+1)*w0
    V1=(k+1)*v0

    print(V1+DP[W1])

0