Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [0 for _ in range(W + 1)]
for w, v in WV:
	for tw in range(W, w - 1, -1):
		dp[tw] = max(dp[tw], dp[tw - w] + v)
	#print(dp)
print(max(dp))


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, W = map(int, input().split())
	WV = [list(map(int, input().split())) for _ in range(N)]

	dp = [0] * (W + 1)
	for w, v in WV:
		for n in range(W, w - 1, -1):
			dp[n] = max(dp[n], dp[n - w] + v)
		#for t in dp:
		#	print("{:4d}".format(t), end="")
		#print()
	return max(dp)

print(main())


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
def chmax(a, b):
	if a < b:
		return b
	return a

def main():
	N, W = map(int, input().split())
	WV = [list(map(int, input().split())) for _ in range(N)]

	dp = [0] * (W + 1)
	for w, v in WV:
		for sumw in range(W, w - 1, -1):
			dp[sumw] = chmax(dp[sumw], dp[sumw - w] + v)
		#for x in dp:
		#	print("{:4d}".format(x), end="")
		#print()
	return max(dp)

print(main())


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, W = map(int, input().split())
	WV = [list(map(int, input().split())) for _ in range(N)]

	dp = [0] * (W + 1)
	for w, v in WV:
		for sumw in range(W, w - 1, -1):
			dp[sumw] = max([dp[sumw], dp[sumw - w] + v])
		#for x in dp:
		#	print("{:4d}".format(x), end="")
		#print()
	return max(dp)

print(main())


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (W + 1)
#for n in range(N):
#	w, v = WV[n]
for w, v in WV:
	for sumw in range(W, w - 1, -1):
		#dp[sumw] = max([dp[sumw], dp[sumw - w] + v])
		if dp[sumw] < dp[sumw - w] + v:
			dp[sumw] = dp[sumw - w] + v
	#for x in dp:
	#	print("{:4d}".format(x), end="")
	#print()
print(max(dp))


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (W + 1)
for n in range(N):
	w, v = WV[n]
	for sumw in range(W, w - 1, -1):
		#dp[sumw] = max([dp[sumw], dp[sumw - w] + v])
		if dp[sumw] < dp[sumw - w] + v:
			dp[sumw] = dp[sumw - w] + v
	#for x in dp:
	#	print("{:4d}".format(x), end="")
	#print()
print(max(dp))


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (W + 1)
for n in range(N):
	w, v = WV[n]
	for sumw in range(W, w - 1, -1):
		dp[sumw] = max([dp[sumw], dp[sumw - w] + v])
	#for x in dp:
	#	print("{:4d}".format(x), end="")
	#print()
print(max(dp))


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (W + 1)
for n in range(N):
	w, v = WV[n]
	for sumw in range(W, w - 1, -1):
		dp[sumw] = max(dp[sumw], dp[sumw - w] + v)
	#for x in dp:
	#	print("{:4d}".format(x), end="")
	#print()
print(max(dp))


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (W + 1)
for n in range(N):
	w, v = WV[n]
	for sumw in range(W, -1, -1):
		if sumw + w <= W:
			dp[sumw + w] = max(dp[sumw + w], dp[sumw] + v)
	#for x in dp:
	#	print("{:4d}".format(x), end="")
	#print()
print(max(dp))


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]
for n in range(1, N + 1):
	w, v = WV[n - 1]
	for sumw in range(W + 1):
		dp[n][sumw] = max(dp[n][sumw], dp[n - 1][sumw])
		if sumw + w <= W:
			dp[n][sumw + w] = max(dp[n][sumw + w], dp[n - 1][sumw] + v)
"""
for x in dp:
	for y in x:
		print("{:4d}".format(y), end="")
	print()
"""
print(dp[-1][-1])


Fixed submission:
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())