Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0][0] = 0

for i in range(1,n+1):
    for before_w in range(w):
        #i番目の品物を選ばない場合
        dp_table[i][before_w] = max(dp_table[i][before_w], dp_table[i-1][before_w])
        #i番目の品物を選ぶ場合
        if wv[i-1][0]+before_w <= w and dp_table[i-1][before_w] >= 0:
            dp_table[i][wv[i-1][0]+before_w] = max(dp_table[i][wv[i-1][0]+before_w], dp_table[i-1][before_w] + wv[i-1][1])
        else:
            continue

result = 0

for y in range(w+1):
    tempresult = max(dp_table[n])
    result=max(result,tempresult)

print(result)

#pprint(dp_table)



Fixed submission:
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0] = [0]*(w+1)

#sum_w以下の重さの時のvalueの合計の最大を求めていく。

for i in range(1,n+1):
    for sum_w in range(w+1):
        #i番目の品物を選ばない場合
        dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w])
        #i番目の品物を選ぶ場合
        if sum_w >= wv[i-1][0]:
            dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            continue


result = dp_table[n][w]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0][0] = 0

for i in range(1,n+1):
    for before_w in range(w):
        #i番目の品物を選ばない場合
        dp_table[i][before_w] = max(dp_table[i][before_w], dp_table[i-1][before_w])
        #i番目の品物を選ぶ場合
        if wv[i-1][0]+before_w <= w and dp_table[i-1][before_w] >= 0:
            dp_table[i][wv[i-1][0]+before_w] = max(dp_table[i][wv[i-1][0]+before_w], dp_table[i-1][before_w] + wv[i-1][1])
        else:
            continue

result = 0

for y in range(w+1):
    tempresult = max(dp_table[n])
    result=max(result,tempresult)

print(result)

#pprint(dp_table)



Fixed submission:
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0] = [0]*(w+1)

#sum_w以下の重さの時のvalueの合計の最大を求めていく。

for i in range(1,n+1):
    for sum_w in range(w+1):
        #i番目の品物を選ばない場合
        dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w])
        #i番目の品物を選ぶ場合
        if sum_w >= wv[i-1][0]:
            dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            continue


result = dp_table[n][w]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(n+1) for _ in range(w+1)]

dp_table[0][0] = 0

for i in range(1,n+1):
    for before_w in range(w):
        #i番目の品物を選ばない場合
        dp_table[before_w][i] = max(dp_table[before_w][i], dp_table[before_w][i-1])
        #i番目の品物を選ぶ場合
        if wv[i-1][0]+before_w <= w:
            dp_table[wv[i-1][0]+before_w][i] = max(dp_table[wv[i-1][0]+before_w][i], dp_table[before_w][i-1] + wv[i-1][1])
        else:
            continue

result = 0

for y in range(w+1):
    result = max(result,dp_table[y][-1])

print(result)

Fixed submission:
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0] = [0]*(w+1)

#sum_w以下の重さの時のvalueの合計の最大を求めていく。

for i in range(1,n+1):
    for sum_w in range(w+1):
        #i番目の品物を選ばない場合
        dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w])
        #i番目の品物を選ぶ場合
        if sum_w >= wv[i-1][0]:
            dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            continue


result = dp_table[n][w]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(n+1) for _ in range(w+1)]

dp_table[0][0] = 0

for i in range(1,n+1):
    for before_w in range(w):
        #i番目の品物を選ばない場合
        dp_table[before_w][i] = max(dp_table[before_w][i], dp_table[before_w][i-1])
        #i番目の品物を選ぶ場合
        if wv[i-1][0]+before_w <= w:
            dp_table[wv[i-1][0]+before_w][i] = max(dp_table[wv[i-1][0]+before_w][i], dp_table[before_w][i-1] + wv[i-1][1])
        else:
            continue

result = 0

for y in range(w+1):
    result = max(result,max(dp_table[y]))

print(result)

Fixed submission:
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0] = [0]*(w+1)

#sum_w以下の重さの時のvalueの合計の最大を求めていく。

for i in range(1,n+1):
    for sum_w in range(w+1):
        #i番目の品物を選ばない場合
        dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w])
        #i番目の品物を選ぶ場合
        if sum_w >= wv[i-1][0]:
            dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            continue


result = dp_table[n][w]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(n+1) for _ in range(w+1)]

dp_table[0][0] = 0

for i in range(1,n+1):
    for before_w in range(w):
        #i番目の品物を選ばない場合
        dp_table[before_w][i] = max(dp_table[before_w][i], dp_table[before_w][i-1])
        #i番目の品物を選ぶ場合
        if wv[i-1][0]+before_w <= w:
            dp_table[wv[i-1][0]+before_w][i] = max(dp_table[wv[i-1][0]+before_w][i], dp_table[before_w][i-1] + wv[i-1][1])
        else:
            continue

result_list=[]

for y in range(w+1):
    result_list.append(max(dp_table[y]))

print(max(result_list))

Fixed submission:
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0] = [0]*(w+1)

#sum_w以下の重さの時のvalueの合計の最大を求めていく。

for i in range(1,n+1):
    for sum_w in range(w+1):
        #i番目の品物を選ばない場合
        dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w])
        #i番目の品物を選ぶ場合
        if sum_w >= wv[i-1][0]:
            dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            continue


result = dp_table[n][w]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(n+1) for _ in range(w+1)]

dp_table[0][0] = 0

for i in range(1,n+1):
    for before_w in range(w):
        #i番目の品物を選ばない場合
        dp_table[before_w][i] = max(dp_table[before_w][i], dp_table[before_w][i-1])
        #i番目の品物を選ぶ場合
        if wv[i-1][0]+before_w <= w:
            dp_table[wv[i-1][0]+before_w][i] = max(dp_table[wv[i-1][0]+before_w][i], dp_table[before_w][i-1] + wv[i-1][1])
        else:
            continue

result_list=[]

for y in range(w+1):
    result_list.append(max(dp_table[y]))

print(max(result_list))

Fixed submission:
from pprint import pprint

n,w = map(int,input().split())

wv = [list(map(int,input().split())) for _ in range(n)]


dp_table = [[-float("inf")]*(w+1) for _ in range(n+1)]

dp_table[0] = [0]*(w+1)

#sum_w以下の重さの時のvalueの合計の最大を求めていく。

for i in range(1,n+1):
    for sum_w in range(w+1):
        #i番目の品物を選ばない場合
        dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w])
        #i番目の品物を選ぶ場合
        if sum_w >= wv[i-1][0]:
            dp_table[i][sum_w] = max(dp_table[i][sum_w], dp_table[i-1][sum_w-wv[i-1][0]] + wv[i-1][1])
        else:
            continue


result = dp_table[n][w]
print(result)