Buggy python submission (verdict: Time Limit Exceeded):
n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

prevdp = [0]*(W+1)
tempdp = [0]*(W+1)

for i in range(1,n+1):
    wI = weights[i-1]
    vI = values[i-1]
    
    for j in range(1,W+1):
        if wI>j:
            tempdp[j] = prevdp[j]
        else:
            tempdp[j] = max(prevdp[j],vI+prevdp[j-wI])
    prevdp = tempdp[:]

print(prevdp[-1])


Fixed submission:
import numpy as np

n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp  = np.zeros(W+1)

for i in range(1,n+1):
    w = weights[i-1]
    v = values[i-1]
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp = [[0]*(W+1) for i in range(n+1)]

for i in range(1,n+1):
    wI = weights[i-1]
    vI = values[i-1]
    for j in range(1,W+1):
        if wI>j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],vI+dp[i-1][j-wI])

print(dp[-1][-1])


Fixed submission:
import numpy as np

n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp  = np.zeros(W+1)

for i in range(1,n+1):
    w = weights[i-1]
    v = values[i-1]
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
n,w = (int(i) for i in input().split())
allItems = [[int(i) for i in input().split()] for j in range(n)]
##weight,value
allItems.sort(key = lambda x:x[0])
allItems.sort(key = lambda x:-x[1])
##print(allItems)
##print()
def getMaxSum(items,emptyWt):
    if emptyWt==0:
        return 0
    if emptyWt==1:
        for i in items:
            if i[0]==1:
                return i[1]
        return 0
    prevWt = {}
    maxRes = -1
    for i in range(len(items)):
        wt,val = items[i]
        if (wt in prevWt) or wt>emptyWt:
            continue
        prevWt[wt]=0
        res = val+getMaxSum(items[:i]+items[i+1:],emptyWt-wt)
        if res>maxRes:
            maxRes = res
    return maxRes
        
prevWt = {}
maxRes = -1
for i in range(n):
    wt,val = allItems[i]
    if wt in prevWt:
        continue
    prevWt[wt]=0
    res = val+getMaxSum(allItems[:i]+allItems[i+1:],w-wt)
    if res>maxRes:
        maxRes = res
print(maxRes)


Fixed submission:
import numpy as np

n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp  = np.zeros(W+1)

for i in range(1,n+1):
    w = weights[i-1]
    v = values[i-1]
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

print(int(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
n,w = (int(i) for i in input().split())
allItems = [[int(i) for i in input().split()] for j in range(n)]

allItems.sort(key = lambda x:x[0])
allItems.sort(key = lambda x:-x[1])

def getMaxSum(items,emptyWt):
    if emptyWt==0:
        return 0
    if emptyWt==1:
        for i in items:
            if i[0]==1:
                return i[1]
        return 0
    prevWt = {}
    maxRes = -1
    for i in range(len(items)):
        wt,val = items[i]
        if (wt in prevWt) or wt>emptyWt:
            continue
        prevWt[wt]=0
        res = val+getMaxSum(items[:i]+items[i+1:],emptyWt-wt)
        if res>maxRes:
            maxRes = res
    return maxRes
        
prevWt = {}
maxRes = -1
for i in range(n):
    wt,val = allItems[i]
    if wt in prevWt:
        continue
    prevWt[wt]=0
    res = val+getMaxSum(allItems[:i]+allItems[i+1:],w-wt)
    if res>maxRes:
        maxRes = res
print(maxRes)


Fixed submission:
import numpy as np

n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp  = np.zeros(W+1)

for i in range(1,n+1):
    w = weights[i-1]
    v = values[i-1]
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

print(int(dp[-1]))