Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

DP = dict()
DP[W] = 0

def maxv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    DPpre = DP.copy()
    for i in DPpre:
        if i - w >= 0:
            maxv(i-w, DPpre[i]+v)

print(max((DP[x] for x in DP)))


Fixed submission:
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

DP = dict()
DP[W] = 0

def maxv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    DPpre = DP.copy()
    for i in DPpre:
        if i - w >= 0:
            maxv(i-w, DPpre[i]+v)

print(max((DP[x] for x in DP)))


Fixed submission:
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

DP = dict()
DP[W] = 0
DPpre = dict()

def maxv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v > DP[i]:
            DP[i] = v
ls = list(list(map(int, input().split())) for _ in range(N))

for w, v in sorted(ls, reverse=True):
    DPpre, DP = DP, DPpre
    for i in DPpre:
        maxv(i, DPpre[i])
        if i - w >= 0:
            maxv(i-w, DPpre[i]+v)

print(max((DP[x] for x in DP)))


Fixed submission:
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break

Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
dp = [-1 for _ in range(w + 1)]
dp[0] = 0
ans = 0
for w, v in (map(int, input().split()) for _ in range(n)):
    for i in range(len(dp) - 1, w - 1, -1):
        if dp[i - w] >= 0:
            dp[i] = max(dp[i - w] + v, v, dp[i])
            ans = max(ans, dp[i])
print(ans)

Fixed submission:
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

DP = dict()
DP[W] = 0
DPpre = dict()

def maxv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    DPpre, DP = DP, DPpre
    for i in DPpre:
        maxv(i, DPpre[i])
        if i - w >= 0:
            maxv(i-w, DPpre[i]+v)

print(max((DP[x] for x in DP)))


Fixed submission:
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break

Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())

DP = [-1] * (W+1)
DP[W] = 0

def maxv(i, v):
    if i >= 0:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    for i in range(1, W+1):
        if DP[i] >= 0:
            maxv(i-w, DP[i]+v)
            maxv(0, DP[i-w])

print(DP[0])


Fixed submission:
N, W = map(int, input().split())

IN = list(list(map(int, input().split())) for _ in range(N))
sumw = 0
sumv = 0
for w, v in IN:
    sumw += w
    sumv += v

DP = dict()
DP[sumv] = sumw

def minv(i, v):
    if not DP.get(i):
        DP[i] = v
    else:
        if v < DP[i]:
            DP[i] = v

for w, v in IN:
    DPpre = DP.copy()
    for i in DPpre:
        minv(i-v, DPpre[i]-w)

for v in sorted(DP, reverse=True):
    if DP[v] <= W:
        print(v)
        break