Buggy python submission (verdict: Time Limit Exceeded):
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(a[0])]

result = []

max_weight = a[1]

def calc(i, queue):
    if len(b) <= i:
        return

    current = b[i]
    prev = queue[-1] if 0 < len(queue) else [0, 0] 
    
    if current[0] + prev[0] <= max_weight:
        result.append(prev[1] + current[1])
    
    next_queue = queue[:]
    next_queue.append([prev[0] + current[0], prev[1] + current[1]])
    calc(i + 1, next_queue)
    calc(i + 1, queue)

calc(0, [])

print(max(result))

Fixed submission:
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(a[0])]

max_index = a[0]
max_weight = a[1]

dp = [ [0] * (max_weight + 1) for j in range(max_index + 1)]

def solve():
    for i in range(max_index - 1, -1, -1):
        for j in range(max_weight + 1):
            if (j < b[i][0]):
                dp[i][j] = dp[i + 1][j]
            else:
                dp[i][j] = max([dp[i + 1][j], dp[i + 1][j - b[i][0]] + b[i][1]])
    print(dp[0][max_weight])

solve()

Buggy python submission (verdict: Time Limit Exceeded):
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(a[0])]

result = []

max_weight = a[1]

def calc(i, queue):
    if len(b) <= i:
        return

    current = b[i]
    # print(queue)
    # print(i - 1)
    prev = queue[-1] if 0 < len(queue) else [0, 0] 
    
    if current[0] + prev[0] <= max_weight:
        result.append(prev[1] + current[1])
    
    next_queue = queue[:]
    next_queue.append([prev[0] + current[0], prev[1] + current[1]])
    # print(next_queue)
    # print(queue)
    calc(i + 1, next_queue)
    calc(i + 1, queue)

calc(0, [])

print(max(result))

Fixed submission:
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(a[0])]

max_index = a[0]
max_weight = a[1]

dp = [ [0] * (max_weight + 1) for j in range(max_index + 1)]

def solve():
    for i in range(max_index - 1, -1, -1):
        for j in range(max_weight + 1):
            if (j < b[i][0]):
                dp[i][j] = dp[i + 1][j]
            else:
                dp[i][j] = max([dp[i + 1][j], dp[i + 1][j - b[i][0]] + b[i][1]])
    print(dp[0][max_weight])

solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, W, weightValues):
    dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
    for i in range(1, N + 1):
        w, v = weightValues[i - 1]
        for j in range(1, W + 1):
            if j < w:  # you cant take it
                dp[i][j] = dp[i - 1][j]
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
    print(dp[N][W])


def iln(): return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
    w_v.append(iln())

solve(N, W, w_v)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Runtime Error):
def solve(N, W, weightValues):
    dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
    for i in range(1, N + 1):
        w, v = weightValues[i]
        for j in range(1, W + 1):
            if j < w: # you cant take it
                dp[i][j] = dp[i - 1][j]
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
    print(dp[N][W])

def iln(): return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
    w_v.append(iln())

solve(N, W, w_v)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Runtime Error):
def solve(N, W, weightValues):
    dp = [0] * (W + 1)
    s = 0
    for w, v in weightValues:
        s += w # why ?
        for i in range(min(W, s), w - 1, -1): # why min(W, s)
	    	dp[i] = max(dp[i], dp[i - w] + v)

    print(max(dp))

def iln(): return list(map(int, input().split()))

N, W = iln()
w_v = []
for i in range(N):
  w_v.append(iln())
  
solve(N, W, w_v)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Runtime Error):
def solve(N, W, weightValues):
    dp = [0] * (W + 1)
    s = 0
    for w, v in weightValues:
        s += w # why ?
        for i in range(min(W, s), w - 1, -1): # why min(W, s)
	    	dp[i] = max(dp[i], dp[i - w] + v)

    print(max(dp))

def iln(): return list(map(int, input().split()))

N, W = iln()
w_v = []
for i in range(N):
  w_v.append(iln())
  
solve(N, W, w_v)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, W, weight_values):
      dp = [0 for _ in range(W + 1)]
     
      for i in range(N):
        wi, vi = weight_values[i]
        for w in range(W, wi - 1, -1): # loop from W down to wi
          if dp[w - wi] + vi > dp[w]:
            dp[w] = dp[w - wi] + vi
     
      print(dp[W])
    
def iln(): return list(map(int, input().split()))

N, W = iln()
w_v = []
for i in range(N):
	w_v.append(iln())

solve(N, W, w_v)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, W):
    dp = [0] * (W + 1)
    for item in range(1, N + 1):
        w, v = list(map(int, input().split()))
        for i in range(W, w - 1, -1):  #
            if v + dp[i - w] > dp[i]:
                dp[i] = v + dp[i - w]

    print(max(dp))


N, W = map(int, input().split())
solve(N, W)


Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, W, weightValues):
    dp = [0] * (W + 1)
    for item in range(1, N + 1):
        w, v = weightValues[item - 1]
        for i in range(W, w - 1, -1):  #
            dp[i] = max(dp[i], v + dp[i - w])

    print(max(dp))


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

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, W, weight_values):
    dp = [0 for _ in range(W + 1)]
    for i in range(N):
        wi, vi = weight_values[i]
        for w in range(W, wi - 1, -1):
            dp[w] = max(dp[w], vi + dp[w - wi])
    print(dp[W])

def iln():
    return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
    w_v.append(iln())

solve(N, W, w_v)

Fixed submission:

N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))