Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
I = [list(map(int, input().split())) for i in range(N)]
dp = [0] * (W+1)

for i in range(N):
  wi, vi = I[i]
  for w in range(W, wi-1, -1):
    dp[w] = max(dp[w], dp[w-wi]+vi)

print(dp[W])


Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [0 for i in range(W+1)]

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

print(dp[W])


Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
dp = [0 for i in range(W+1)]

for i in range(N):
  wi, vi = map(int, input().split())
  for w in range(W, wi-1, -1):
    dp[w] = max(dp[w], dp[w-wi]+vi)

print(max(dp))

Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [0 for i in range(W+1)]

for i in range(N):
  wi, vi = map(int, input().split())
  for w in range(W, wi-1, -1):
    dp[w] = max(dp[w], dp[w-wi]+vi)

print(max(dp))


Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [0]*(W+1)

for i in range(N):
  wi, vi = map(int, input().split())
  for w in range(W, wi-1, -1):
    dp[w] = max(dp[w], dp[w-wi]+vi)

print(max(dp))


Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
  wi, vi = map(int, input().split())
  for w in range(1, W+1):
    if w - wi < 0:
      dp[i][w] = dp[i-1][w]
    else:
      dp[i][w] = max(dp[i-1][w], dp[i-1][w-wi]+vi)

print(dp[N][W])


Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
class Item:
  def __init__(self, w, v):
    self.w = w
    self.v = v

N, W = map(int, input().split())
items = [Item(0, 0)] + [Item(*map(int, input().split())) for i in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
  item = items[i]
  for w in range(1, W+1):
    if w - item.w < 0:
      dp[i][w] = dp[i-1][w]
    else:
      dp[i][w] = max(dp[i-1][w], dp[i-1][w-item.w]+item.v)

print(dp[N][W])


Fixed submission:
import sys
input = sys.stdin.readline
 
def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))
 
if __name__ == "__main__":
    main()