Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!


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

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

for i in range(1, N+1):
    w, v = map(int, input().split())
    for j in range(W+1):
        if j-w >= 0:
            dp[i][j] = max(dp[i-1][j-w]+v, dp[i][j])
        dp[i][j] = max(dp[i-1][j], dp[i][j])

# print(dp)
print(dp[N][W])

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N, W = map(int, input().split())
   
dp = [-1] * (W+1)
dp[0] = 0

for i in range(1, N+1):
    w, v = map(int, input().split())
    for j in range(W-w, -1, -1):
        if dp[j] == -1:
            continue
        if dp[j+w] < dp[j]+v:
            dp[j+w] = dp[j] + v

# for i in range(N+1):
#     print(dp[i])

print(max(dp))

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

N, W = map(int, sys.stdin.buffer.readline().split())
   
dp = [-1] * (W+1)
dp[0] = 0

for i in range(1, N+1):
    w, v = map(int, sys.stdin.buffer.readline().split())
    for j in range(W-w, -1, -1):
        if dp[j] == -1:
            continue
        if dp[j+w] < dp[j]+v:
            dp[j+w] = dp[j] + v

# for i in range(N+1):
#     print(dp[i])

print(max(dp))

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import numpy as np

N, W = map(int, sys.stdin.buffer.readline().split())
   
dp = np.ones(W+1, dtype=int) * -1
dp[0] = 0

for i in range(1, N+1):
    w, v = map(int, sys.stdin.buffer.readline().split())
    for j in range(W-w, -1, -1):
        if dp[j] == -1:
            continue
        if dp[j+w] < dp[j]+v:
            dp[j+w] = dp[j] + v

# for i in range(N+1):
#     print(dp[i])

print(max(dp))

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import numpy as np

N, W = map(int, sys.stdin.buffer.readline().split())
   
dp = np.zeros((N+1, W+1), dtype=int)

for i in range(1, N+1):
    w, v = map(int, sys.stdin.buffer.readline().split())
    for j in range(W+1):
        if j-w >= 0:
            dp[i,j] = max(dp[i,j], dp[i-1,j-w]+v)
        dp[i,j] = max(dp[i,j], dp[i-1,j])

# for i in range(N+1):
#     print(dp[i])

print(dp[N,W])

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np

N, W = map(int, sys.stdin.buffer.readline().split())
   
dp = np.zeros((N+1, W+1), dtype=int)

for i in range(1, N+1):
    w, v = map(int, sys.stdin.buffer.readline().split())
    for j in range(W+1):
        if j-w[i] >= 0:
            dp[i,j] = max(dp[i,j], dp[i-1,j-w[i]]+v[i])
        dp[i,j] = max(dp[i,j], dp[i-1,j])

# for i in range(N+1):
#     print(dp[i])

print(dp[N,W])

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import numpy as np

N, W = map(int, sys.stdin.buffer.readline().split())
w, v = np.zeros(N+10, dtype=int), np.zeros(N+10, dtype=int)

for i in range(1, N+1):
    w[i], v[i] = map(int, sys.stdin.buffer.readline().split())
   
dp = np.zeros((N+1, W+1), dtype=int)

for i in range(1, N+1):
    for j in range(W+1):
        if j-w[i] >= 0:
            dp[i,j] = max(dp[i,j], dp[i-1,j-w[i]]+v[i])
        dp[i,j] = max(dp[i,j], dp[i-1,j])

# for i in range(N+1):
#     print(dp[i])

print(dp[N,W])

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

N, W = map(int, sys.stdin.buffer.readline().split())
w, v = [0 for _ in range(N+10)], [0 for _ in range(N+10)]

for i in range(1, N+1):
    w[i], v[i] = map(int, sys.stdin.buffer.readline().split())
   
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(1, N+1):
    for j in range(W+1):
        if j-w[i] >= 0:
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]]+v[i])
        dp[i][j] = max(dp[i][j], dp[i-1][j])

# for i in range(N+1):
#     print(dp[i])

print(dp[N][W])

Fixed submission:
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()