結果

問題 No.527 ナップサック容量問題
ユーザー 👑 H20H20
提出日時 2022-02-14 21:48:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 78,792 KB
最終ジャッジ日時 2023-09-11 16:48:41
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
76,988 KB
testcase_01 AC 78 ms
77,256 KB
testcase_02 AC 76 ms
77,260 KB
testcase_03 WA -
testcase_04 AC 74 ms
77,120 KB
testcase_05 AC 117 ms
77,812 KB
testcase_06 AC 153 ms
77,592 KB
testcase_07 WA -
testcase_08 AC 108 ms
78,028 KB
testcase_09 AC 75 ms
76,992 KB
testcase_10 WA -
testcase_11 AC 128 ms
77,876 KB
testcase_12 AC 111 ms
77,768 KB
testcase_13 AC 152 ms
78,140 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 79 ms
77,184 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 81 ms
77,172 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 122 ms
77,992 KB
testcase_29 WA -
testcase_30 AC 86 ms
77,820 KB
testcase_31 WA -
testcase_32 AC 123 ms
77,692 KB
testcase_33 AC 115 ms
77,628 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
VW = [list(map(int, input().split())) for _ in range(N)]
V = int(input())
DP = [0]*(100010)
DPM = [0]*(100010)
for v,w in VW:
    for i in reversed(range(100010)):
        if DP[i]>0:
            DP[i+v]=max(DP[i+v],DP[i]+w)
            if DPM[i+v]==0:
                DPM[i+v]=DPM[i]+w
            else:
                DPM[i+v]=min(DPM[i+v],DPM[i]+w)        
    DP[v]=max(DP[v],w)
    if DPM[v]==0:
        DPM[v]=w
    else:
        DPM[v]=min(DPM[v],w)


print(max(1,DPM[V]))
ma = 10**18
for i in range(V+1,100010):
    if DP[i]>0 and ma>DP[i]:
        ma=DP[i]
if ma!=10**18:
    print(ma-1)
else:
    print('inf')
0