Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)
INF=int(10e9)


def knapSack(i,w):
    if i<0:
        return 0
    elif dp[i].get(w)!=None:
        return dp[i][w]
    elif wt[i]>w:
        dp[i][w]=knapSack(i-1,w)
    else:
        dp[i][w]=max(val[i]+knapSack(i-1,w-wt[i]),knapSack(i-1,w))
    return dp[i][w]

n,w=mdata()
val=[0]*(n)
wt=[0]*(n)
for i in range(n):
    wt[i],val[i]=mdata()
dp=[{} for i in range(n)]
print(knapSack(n-1,w))

Fixed submission:
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)
INF=int(10e9)


def knapSack(V):
    for i in range(n + 1):
        for v in range(V + 1):
            if v == 0:
                K[i][v] = 0
            elif val[i - 1] <= v:
                K[i][v] = min(wt[i - 1] + K[i - 1][v - val[i - 1]], K[i - 1][v])
            else:
                K[i][v] = K[i - 1][v]

    return K[n][V]

n,w=mdata()
val=[0]*(n)
wt=[0]*(n)
for i in range(n):
    wt[i],val[i]=mdata()
V=100005
K = [[1000000007 for x in range(V + 1)] for x in range(n + 1)]
knapSack(V)
m=0
for i in range(n + 1):
    for v in range(V + 1):
        if 1<=K[i][v]<=w :
            m=max(m,v)
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)
INF=int(10e9)


def knapSack(i,w):
    if i<0:
        return 0
    elif dp[i].get(w)!=None:
        return dp[i][w]
    elif wt[i]>w:
        dp[i][w]=knapSack(i-1,w)
    else:
        dp[i][w]=max(val[i]+knapSack(i-1,w-wt[i]),knapSack(i-1,w))
    return dp[i][w]

n,w=mdata()
val=[0]*(n)
wt=[0]*(n)
for i in range(n):
    wt[i],val[i]=mdata()
dp=[{} for i in range(n)]
print(knapSack(n-1,w))

Fixed submission:
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)
INF=int(10e9)


def knapSack(V):
    for i in range(n + 1):
        for v in range(V + 1):
            if v == 0:
                K[i][v] = 0
            elif val[i - 1] <= v:
                K[i][v] = min(wt[i - 1] + K[i - 1][v - val[i - 1]], K[i - 1][v])
            else:
                K[i][v] = K[i - 1][v]

    return K[n][V]

n,w=mdata()
val=[0]*(n)
wt=[0]*(n)
for i in range(n):
    wt[i],val[i]=mdata()
V=100005
K = [[1000000007 for x in range(V + 1)] for x in range(n + 1)]
knapSack(V)
m=0
for i in range(n + 1):
    for v in range(V + 1):
        if 1<=K[i][v]<=w :
            m=max(m,v)
print(m)