Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
c,p=map(int,input().split())
dp[c]=p
 
def ans(n,w):
  for _ in range(1,n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      if dp[j]<dp[j-c]+p:
        dp[j]=dp[j-c]+p
  return max(dp)
print(ans(n,w))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

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

n,w=map(int,input().split())
dp=[0]*(w+1)
c,p=map(int,input().split())
dp[c]=p

def ans(n,w):
  for _ in range(1,n):
    c,p=map(int,input().split())
    for j in range(w,c,-1):
      if dp[j-c] != 0 and dp[j]<dp[j-c]+p:
        dp[j]=dp[j-c]+p
    if dp[c] < p:
      dp[c]=p
  return max(dp)
print(ans(n,w))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
dp=[0 for j in range(w+1)]
c,p=map(int,input().split())
dp[c]=p
for i in range(1,n):
  c,p=map(int,input().split())
  for j in range(w,c,-1):
    if dp[j-c] != 0 and dp[j]<dp[j-c]+p:
      dp[j]=dp[j-c]+p
  if dp[c] < p:
    dp[c]=p
print(max(dp))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

Buggy python submission (verdict: Runtime Error):
n,w=map(int,input().split())
dp=[0 for j in range(w+1)]
c,p=map(int,input().split())
dp[c]=p
for i in range(1,n+1):
  c,p=map(int,input().split())
  for j in range(w,1,-1):
    if dp[j]<dp[j-c]+p:
      dp[j]=dp[j-c]+p    
print(max(dp))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
dp=[{} for j in range(n+1)]
c,p=map(int,input().split())
dp[1][c]=p
for i in range(2,n+1):
  c,p=map(int,input().split())
  for j in dp[i-1].keys():
    if j+c<=w and dp[i-1][j] != 0:
      if j+c in dp[i-1]:
        dp[i][j+c]=max(dp[i-1][j+c],dp[i-1][j]+p)
      else:
        dp[i][j+c]=dp[i-1][j]+p
    if dp[i-1][j] != 0:
      dp[i][j]=dp[i-1][j]
  if c in dp[i-1]:
    dp[i][c]=max(dp[i-1][c],p)
  else:
    dp[i][c]=p
print(max([dp[n][i] for i in dp[n].keys()]))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
dp=[[0 for i in range(w+1)] for j in range(n+1)]
c,p=map(int,input().split())
dp[1][c]=p
for i in range(2,n+1):
  c,p=map(int,input().split())
  for j in range(w-1,0,-1):
    if j+c<=w and dp[i-1][j] != 0:
      dp[i][j+c]=max(dp[i-1][j+c],dp[i-1][j]+p)
    if dp[i-1][j] != 0:
      dp[i][j]=dp[i-1][j]
  dp[i][c]=max(dp[i-1][c],p)
print(max([dp[n][i] for i in range(w+1)]))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
dp=[[0 for i in range(w+1)] for j in range(n+1)]
c,p=map(int,input().split())
dp[1][c]=p
for i in range(2,n+1):
  c,p=map(int,input().split())
  for j in range(w):
    if dp[i-1][j] != 0:
      dp[i][j]=dp[i-1][j]
  for j in range(w):
    if j+c<=w and dp[i-1][j] != 0:
      dp[i][j+c]=max(dp[i-1][j+c],dp[i-1][j]+p)
  dp[i][c]=max(dp[i-1][c],p)
print(max([dp[n][i] for i in range(w+1)]))

Fixed submission:
import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))