Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    # 見つからなかったとき
    return None


n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
dp = [0]
check = [0]
size = 1
for ww, vv in wv:
    for i in range(size):
        g = ww + check[i]
        v = vv + dp[i]
        if g > w:
            continue
        else:
            search = binary_search(check, g)
            if search:
                if dp[search] < v:
                    dp[search] = v
            else:
                dp.append(v)
                check.append(g)
                size += 1

print(max(dp))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
dp = np.full(n * 1000 + 1, w + 1, dtype=int)
dp[0] = 0
for x, y in wv:
    dp[y:] = np.minimum(dp[y:], dp[:-y] + x)
print(np.max(np.where(dp <= w)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
dp = [0]
check = [0]
size = 1
for ww, vv in wv:
    for i in range(size):
        g = ww + check[i]
        v = vv + dp[i]
        if g > w:
            continue
        else:
            if g in check:
                index = check.index(g)
                if dp[index] < v:
                    dp[index] = v
            else:
                dp.append(v)
                check.append(g)
                size += 1

print(max(dp))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
dp = np.full(n * 1000 + 1, w + 1, dtype=int)
dp[0] = 0
for x, y in wv:
    dp[y:] = np.minimum(dp[y:], dp[:-y] + x)
print(np.max(np.where(dp <= w)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
inf = float('inf')
dp = [0]
check = [0]
for ww, vv in wv:
    for i in range(len(dp)):
        g = ww + check[i]
        v = vv + dp[i]
        if g > w:
            continue
        else:
            if g in check:
                index = check.index(g)
                if dp[index] < v:
                    dp[index] = v
            else:
                dp.append(v)
                check.append(g)

print(max(dp))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
dp = np.full(n * 1000 + 1, w + 1, dtype=int)
dp[0] = 0
for x, y in wv:
    dp[y:] = np.minimum(dp[y:], dp[:-y] + x)
print(np.max(np.where(dp <= w)))