Problem p03164 (python)

Fixed submission:
import sys
import math
from collections import deque
import copy

INF = 10 ** 9 + 7
N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    tempW, tempV = map(int, input().split())
    weight.append(tempW)
    value.append(tempV)

dp = [[INF for _ in range(N * 1000 + 1)] for _ in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    for l in range(N * 1000 + 1):
        if l - value[i - 1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - value[i - 1]] + weight[i - 1])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 1000 + 1):
    if dp[N][i] <= W:
        ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy
input = sys.stdin.readline
INF = int(float("inf"))
N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    tempW, tempV = map(int, input().split())
    weight.append(tempW)
    value.append(tempV)

dp = [[INF for _ in range(N * 1000 + 1)] for _ in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    for l in range(N * 1000 + 1):
        if l - value[i - 1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - value[i - 1]] + weight[i - 1])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 1000 + 1):
    if dp[N][i] <= W:
        ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

INF = 10 ** 9 + 7
N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    tempW, tempV = map(int, input().split())
    weight.append(tempW)
    value.append(tempV)

dp = [[INF for _ in range(N * 300)] for _ in range(N)]
for i in range(value[0]):
    dp[0][i] = weight[0]

for i in range(N):
    for l in range(N * 300):
        if l - value[i] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - value[i]] + weight[i])
        else:
            dp[i][l] = min(weight[i], dp[i - 1][l])
for i in range(N * 300 - 1):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i + 1)
        break
    elif i == N * 300 - 2:
        print(N * 300)

Buggy submission (verdict: Runtime Error):
INF = 10 ** 9 + 7
N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    tempW, tempV = map(int, input().split())
    weight.append(tempW)
    value.append(tempV)

dp = [[INF for _ in range(N * 300)] for _ in range(N)]
for i in range(value[0]):
    dp[0][i] = weight[0]

for i in range(N):
    for l in range(N * 300):
        if l - value[i] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - value[i]] + weight[i])
        else:
            dp[i][l] = min(weight[i], dp[i - 1][l])
for i in range(N * 300 - 1):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i + 1)
        break
    elif i == N * 300 - 2:
        print(N * 300)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300)] for _ in range(N)]

for i in range(wv[0][1]):
    dp[0][i] = wv[0][0]
for i in range(1, N):
    for l in range(N * 300):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i][1]] + wv[i][0])
        else:
            dp[i][l] = min(dp[i - 1][l], wv[i][0])
for i in range(N * 300 - 1):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i+1)
        break

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300 + 1)] for _ in range(N + 1)]

for i in dp:
    i[0] = 0
for i in range(1, wv[0][1] + 1):
    dp[1][i] = wv[0][0]

for i in range(2, N + 1):
    for l in range(1, N * 300 + 1):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i - 1][1]] + wv[i - 1][0])
        elif dp[i][l] == 10 ** 9 + 7:
            dp[i][l] = min(wv[i - 1][0], dp[i - 1][l])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 300):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i)
        break
    elif i == N*300-1:
        print(i+1)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300 + 1)] for _ in range(N + 1)]

for i in dp:
    i[0] = 0
for i in range(1, wv[0][1] + 1):
    dp[1][i] = wv[0][0]

for i in range(2, N + 1):
    for l in range(1, N * 300 + 1):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i - 1][1]] + wv[i - 1][0])
        elif dp[i][l] == 10 ** 9 + 7:
            dp[i][l] = min(wv[i - 1][0], dp[i - 1][l])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 300):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i)
        break
    elif i == N*300-1:
        print(i)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300 + 1)] for _ in range(N + 1)]

for i in dp:
    i[0] = 0
for i in range(1, wv[0][1] + 1):
    dp[1][i] = wv[0][0]

for i in range(2, N + 1):
    for l in range(1, N * 300 + 1):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i - 1][1]] + wv[i - 1][0])
        elif dp[i][l] == 10 ** 9 + 7:
            dp[i][l] = min(wv[i - 1][0], dp[i - 1][l])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 300):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i)
        break
    elif i == N*300-1:
        print(i)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300 + 1)] for _ in range(N + 1)]

for i in dp:
    i[0] = 0
for i in range(1, wv[0][1]+1):
    dp[1][i] = wv[0][0]

for i in range(2, N + 1):
    for l in range(1, N * 300 + 1):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i - 1][1]] + wv[i - 1][0])
        elif dp[i][l] == 10**9+7:
            dp[i][l] = min(wv[i-1][0], dp[i-1][l])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N*300+1):
    if dp[-1][i] <= W < dp[-1][i+1]:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300 + 1)] for _ in range(N + 1)]

for i in dp:
    i[0] = 0
for i in range(1, wv[0][1]+1):
    dp[1][i] = wv[0][0]

for i in range(2, N + 1):
    for l in range(1, N * 300 + 1):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i - 1][1]] + wv[i - 1][0])
        elif dp[i][l] == 10**9+7:
            dp[i][l] = min(wv[i-1][0], dp[i-1][l])
        else:
            dp[i][l] = dp[i - 1][l]
for i, l in enumerate(dp[-1]):
    if l <= W < dp[-1][i + 1]:
        print(i)
        break