Buggy python submission (verdict: Runtime Error):
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))
~                   

Fixed submission:
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]

def dfs(i,w):
    if (i,w) in dic: return dic[(i,w)]
    if i == N or w <=0: 
        dic[(i,w)] = 0
        return 0
    ma = 0 
    res1 = res2 = 0 
    if A[i][0] <=w:
        res1 = dfs(i + 1,w - A[i][0]) + A[i][1]
    res2 = dfs(i + 1,w)
    ma = max(res1,res2)
    dic[(i,w)] = ma
    return ma
dic = {}
res = dfs(0,W)
print(res)

Fixed submission:
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]

def dfs(i,w):
    if (i,w) in dic: return dic[(i,w)]
    if i == N or w <=0: 
        dic[(i,w)] = 0
        return 0
    ma = 0 
    res1 = res2 = 0 
    if A[i][0] <=w:
        res1 = dfs(i + 1,w - A[i][0]) + A[i][1]
    res2 = dfs(i + 1,w)
    ma = max(res1,res2)
    dic[(i,w)] = ma
    return ma
dic = {}
res = dfs(0,W)
print(res)

Fixed submission:
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]

def dfs(i,w):
    if (i,w) in dic: return dic[(i,w)]
    if i == N or w <=0: return 0
    ma = 0 
    res1 = res2 = 0 
    if A[i][0] <=w:
        res1 = dfs(i + 1,w - A[i][0]) + A[i][1]
    res2 = dfs(i + 1,w)
    ma = max(res1,res2)
    dic[(i,w)] = ma
    return ma
dic = {}
res = dfs(0,W)
print(res)

Fixed submission:
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]

def dfs(i,w):
    if (i,w) in dic: return dic[(i,w)]
    if i == N or w <=0: return 0
    ma = 0 
    res1 = res2 = 0 
    if A[i][0] <=w:
        res1 = dfs(i + 1,w - A[i][0]) + A[i][1]
    res2 = dfs(i + 1,w)
    ma = max(res1,res2)
    dic[(i,w)] = ma
    return ma
dic = {}
res = dfs(0,W)
print(res)

Fixed submission:
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]

def dfs(w,s):
    if (w,s) in dic: return dic[(w,s)]
    ma = 0 
    ls = set(s)
    for idx in range(N):
        if idx not in ls and A[idx][0] <= w:
            ls.add(idx)
            res = dfs(w - A[idx][0],tuple(ls)) + A[idx][1]
            ma = max(res,ma)
            ls.remove(idx)
    dic[(w,s)] = ma
    return ma
dic = {}
seen = set()
res = dfs(W,tuple(seen))
print(res)

Fixed submission:
import sys 
sys.setrecursionlimit(2147483647)

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

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))