Buggy python submission (verdict: Time Limit Exceeded):
#EDP-E
import sys
n,W = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for i in range(n)]
dp = [[ float('inf') for i in range(100001)] for _ in range(n)]


dp[0][L[0][1]] = L[0][0]

for i in range(1, n):
    for vb in range(100001):
        if dp[i-1][vb] != float('inf'):
            dp[i][vb] = dp[i-1][vb]
            tmp = min(dp[i][vb + L[i][1]], dp[i-1][vb] + L[i][0])
            if tmp <=W:
                dp[i][vb + L[i][1]] = tmp
                #print(vb + v, dp[i][vb+ v])
    dp[i][L[i][1]] = min(dp[i][L[i][1]], L[i][0])

ans =0
for v, w in enumerate(dp[n-1]):
    if w <=W and ans <=v:
        ans = v
print(ans)

Fixed submission:
import sys
n, limit = map(int, sys.stdin.readline().split()) 
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [dict() for i in range(n)]
#print(dp)
dp[0][L[0][1]] = L[0][0]

for i in range(1, n):
    dp[i][L[i][1]] = min(L[i][0], dp[i-1].get(L[i][1], float('inf')))
    for v, w in dp[i-1].items():
        dp[i][v] = min(dp[i-1][v], dp[i].get(v, float('inf')))
        dp[i][L[i][1] + v] = min(L[i][0] + dp[i-1][v], dp[i-1].get(L[i][1] + v, float('inf'))) 
        
ans = 0
for v, w in dp[-1].items():
    if w <=limit:
        if ans < v:
            ans = v
#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#EDP-E
import sys
n,W = map(int, sys.stdin.readline().split())

dp = [[ float('inf') for i in range(100001)] for _ in range(n)]


w, v = map(int, sys.stdin.readline().split())
dp[0][v] = w

for i in range(1, n):
    w, v = map(int, sys.stdin.readline().split())
    for vb in range(100001):
        if dp[i-1][vb] != float('inf'):
            dp[i][vb] = dp[i-1][vb]
            tmp = min(dp[i][vb + v], dp[i-1][vb] + w)
            if tmp <=W:
                dp[i][vb + v] = tmp
                #print(vb + v, dp[i][vb+ v])
    dp[i][v] = min(dp[i][v], w)

ans =0
for v, w in enumerate(dp[n-1]):
    if w <=W and ans <=v:
        ans = v
print(ans)

Fixed submission:
import sys
n, limit = map(int, sys.stdin.readline().split()) 
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [dict() for i in range(n)]
#print(dp)
dp[0][L[0][1]] = L[0][0]

for i in range(1, n):
    dp[i][L[i][1]] = min(L[i][0], dp[i-1].get(L[i][1], float('inf')))
    for v, w in dp[i-1].items():
        dp[i][v] = min(dp[i-1][v], dp[i].get(v, float('inf')))
        dp[i][L[i][1] + v] = min(L[i][0] + dp[i-1][v], dp[i-1].get(L[i][1] + v, float('inf'))) 
        
ans = 0
for v, w in dp[-1].items():
    if w <=limit:
        if ans < v:
            ans = v
#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#EDP-D, E
import sys
from collections import defaultdict
n, W = map(int, sys.stdin.readline().split())
dp = [defaultdict(int) for _ in range(n)]
#初期設定
w, v = map(int, sys.stdin.readline().split())
dp[0][w] = v
#print(dp)

for i in range(1, n):
    w, v = map(int, sys.stdin.readline().split())
    dp[i][w] = max(dp[i-1].get(w, 0), v)
    for w1, v1 in dp[i-1].items():
        dp[i][w1] = max(dp[i][w1], v1)
        if w+w1<=W:
            dp[i][w1+w] = max(dp[i][w1+w], v1+v)

print(max(dp[-1].values()))

Fixed submission:
import sys
n, limit = map(int, sys.stdin.readline().split()) 
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [dict() for i in range(n)]
#print(dp)
dp[0][L[0][1]] = L[0][0]

for i in range(1, n):
    dp[i][L[i][1]] = min(L[i][0], dp[i-1].get(L[i][1], float('inf')))
    for v, w in dp[i-1].items():
        dp[i][v] = min(dp[i-1][v], dp[i].get(v, float('inf')))
        dp[i][L[i][1] + v] = min(L[i][0] + dp[i-1][v], dp[i-1].get(L[i][1] + v, float('inf'))) 
        
ans = 0
for v, w in dp[-1].items():
    if w <=limit:
        if ans < v:
            ans = v
#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, limit = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
#print(L)
dp = [{} for i in range(n+1)]

for i in range(n):
    Lw, Lv =L[i][0], L[i][1] #①i番目の価値を重さテーブルに代入
    dp[i+1][Lw] = Lv 
    for w, v in dp[i].items():
        dp[i+1][w] = max(dp[i+1].get(w, 0), v) #② 一つ上の行の価値と比べて大きい方を代入
        if w + Lw <=limit:
            dp[i+1][w+Lw] = max(dp[i].get(w+ Lw, 0), Lv + v) #③一つ上の行の価値をループで1つづつ取り出し、i番目の価値と足し合わせる
        
print(max(dp[-1].values()))

Fixed submission:
import sys
n, limit = map(int, sys.stdin.readline().split()) 
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [dict() for i in range(n)]
#print(dp)
dp[0][L[0][1]] = L[0][0]

for i in range(1, n):
    dp[i][L[i][1]] = min(L[i][0], dp[i-1].get(L[i][1], float('inf')))
    for v, w in dp[i-1].items():
        dp[i][v] = min(dp[i-1][v], dp[i].get(v, float('inf')))
        dp[i][L[i][1] + v] = min(L[i][0] + dp[i-1][v], dp[i-1].get(L[i][1] + v, float('inf'))) 
        
ans = 0
for v, w in dp[-1].items():
    if w <=limit:
        if ans < v:
            ans = v
#print(dp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import defaultdict
n, limit= map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

#各重さとi番目の荷物を入れ終わった状態のテーブルをつくる
d = {}
dp = [d.copy() for _ in range(n)]

#初期状態
for w in range(L[0][0], limit+1):
    dp[0][w] = L[0][1]
#print(dp)
for i in range(1, n):
    for w in range(1, limit+1):
        if dp[i-1].get(w-L[i][0]) and dp[i-1].get(w): #キーが存在するなら
            dp[i][w] = max(dp[i-1][w-L[i][0]] + L[i][1], dp[i-1][w])
        elif dp[i-1].get(w) and w==L[i][0]:
            dp[i][w] = max(L[i][1], dp[i-1][w])
        elif dp[i-1].get(w):
            dp[i][w] = dp[i-1][w]
        elif w==L[i][0]:
            dp[i][w] = L[1][1]
    #print(dp)  
print(max(dp[-1].values()))

Fixed submission:
import sys
n, limit = map(int, sys.stdin.readline().split()) 
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [dict() for i in range(n)]
#print(dp)
dp[0][L[0][1]] = L[0][0]

for i in range(1, n):
    dp[i][L[i][1]] = min(L[i][0], dp[i-1].get(L[i][1], float('inf')))
    for v, w in dp[i-1].items():
        dp[i][v] = min(dp[i-1][v], dp[i].get(v, float('inf')))
        dp[i][L[i][1] + v] = min(L[i][0] + dp[i-1][v], dp[i-1].get(L[i][1] + v, float('inf'))) 
        
ans = 0
for v, w in dp[-1].items():
    if w <=limit:
        if ans < v:
            ans = v
#print(dp)
print(ans)