for j in range(W - weight + 1) の+1を忘れて最大重量の場合を更新し忘れるミスpythondef solve(N, W, WV):
values = [0] * (W + 1)
for i in range(N):
next_values = values[:]
weight, value = WV[i]
for j in range(W - weight + 1):
next_values[j + weight] = max(
values[j + weight],
values[j] + value)
values = next_values
return max(values)