Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy as np

N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]

#import sys
#input = sys.stdin.readline
#val = list(input()) #abc
#val=np.array(val)
#index=np.argsort(val[:,0])
#A=val[index,0].tolist()
#B=val[index,1].tolist()
val.sort()
A=[v[0] for v in val]
B=[v[1] for v in val]

#temp=np.zeros((T+1,N))
#Ts=T*np.ones(N-1)
#jun=np.arange(1,N)
#for itemp in range(T):
#    i=itemp
#    if i>=A[0]:
#        temp[i,0]=B[0]
#    if i>0:
#        temp[i,:]=np.amax([temp[i,:],temp[i-1,:]],0)
#    for jtemp in range(N-1):
#        j=jtemp+1
#        temp[i,j]=max(temp[i,j],temp[i,j-1])
#    jnext=np.amin([Ts,i+A[1:]],0)
#    jnext=[int(s) for s in jnext]
#    temp[jnext,jun]=np.amax([temp[i,:-1]+B[1:],temp[jnext,jun]],0)

temp=[[0]*N for i in range(T+1)]

for itemp in range(T):
    i=itemp
    if i>=A[0]:
        temp[i][0]=B[0]
    for jtemp in range(N-1):
        j=jtemp+1
        jbfo=temp[i][j-1]
        ijnow=temp[i][j]
        
        if i>0:
            temp[i][j]=max(ijnow,temp[i-1][j])
            
        temp[i][j]=max(ijnow,jbfo)
        if A[j]<T-i:
            temp[i+A[j]][j]=max(jbfo+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(jbfo+B[j],temp[T][j])
print(int(max(temp[-1][:]))) 

Fixed submission:
# -*- coding: utf-8 -*-

N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]

#import sys
#input = sys.stdin.readline
#val = list(input()) #abc
#val=np.array(val)
#index=np.argsort(val[:,0])
#A=val[index,0].tolist()
#B=val[index,1].tolist()
val.sort()
A=[v[0] for v in val]
B=[v[1] for v in val]

#temp=np.zeros((T+1,N))
#Ts=T*np.ones(N-1)
#jun=np.arange(1,N)
#for itemp in range(T):
#    i=itemp
#    if i>=A[0]:
#        temp[i,0]=B[0]
#    if i>0:
#        temp[i,:]=np.amax([temp[i,:],temp[i-1,:]],0)
#    for jtemp in range(N-1):
#        j=jtemp+1
#        temp[i,j]=max(temp[i,j],temp[i,j-1])
#    jnext=np.amin([Ts,i+A[1:]],0)
#    jnext=[int(s) for s in jnext]
#    temp[jnext,jun]=np.amax([temp[i,:-1]+B[1:],temp[jnext,jun]],0)

temp=[[0]*N for i in range(T+1)]

for itemp in range(T):
    i=itemp
    if i>=A[0]:
        temp[i][0]=B[0]
    for jtemp in range(N-1):
        j=jtemp+1
        jbfo=temp[i][j-1]
        ijnow=temp[i][j]
        
        if i>0:
            temp[i][j]=max(ijnow,temp[i-1][j])
            
        temp[i][j]=max(ijnow,jbfo)
        if A[j]<T-i:
            temp[i+A[j]][j]=max(jbfo+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(jbfo+B[j],temp[T][j])
print(int(max(temp[-1][:])))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import numpy as np
N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]
#import sys
#input = sys.stdin.readline
#val = list(input()) #abc
val=np.array(val)
index=np.argsort(val[:,0])
A=val[index,0]
B=val[index,1]

temp=[[0]*N for i in range(T+1)]
for jtemp in range(N-1):
    j=jtemp+1

    for itemp in range(T):
        i=itemp
        if i>=A[0]:
            temp[i][0]=B[0]
        if i>0:
            temp[i][j]=max(temp[i][j],temp[i-1][j])
            
        temp[i][j]=max(temp[i][j],temp[i][j-1])
        if A[j]<T-i:
            temp[i+A[j]][j]=max(temp[i][j-1]+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(temp[i][j-1]+B[j],temp[T][j])
print(max(temp[-1][:])) 

Fixed submission:
# -*- coding: utf-8 -*-

N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]

#import sys
#input = sys.stdin.readline
#val = list(input()) #abc
#val=np.array(val)
#index=np.argsort(val[:,0])
#A=val[index,0].tolist()
#B=val[index,1].tolist()
val.sort()
A=[v[0] for v in val]
B=[v[1] for v in val]

#temp=np.zeros((T+1,N))
#Ts=T*np.ones(N-1)
#jun=np.arange(1,N)
#for itemp in range(T):
#    i=itemp
#    if i>=A[0]:
#        temp[i,0]=B[0]
#    if i>0:
#        temp[i,:]=np.amax([temp[i,:],temp[i-1,:]],0)
#    for jtemp in range(N-1):
#        j=jtemp+1
#        temp[i,j]=max(temp[i,j],temp[i,j-1])
#    jnext=np.amin([Ts,i+A[1:]],0)
#    jnext=[int(s) for s in jnext]
#    temp[jnext,jun]=np.amax([temp[i,:-1]+B[1:],temp[jnext,jun]],0)

temp=[[0]*N for i in range(T+1)]

for itemp in range(T):
    i=itemp
    if i>=A[0]:
        temp[i][0]=B[0]
    for jtemp in range(N-1):
        j=jtemp+1
        jbfo=temp[i][j-1]
        ijnow=temp[i][j]
        
        if i>0:
            temp[i][j]=max(ijnow,temp[i-1][j])
            
        temp[i][j]=max(ijnow,jbfo)
        if A[j]<T-i:
            temp[i+A[j]][j]=max(jbfo+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(jbfo+B[j],temp[T][j])
print(int(max(temp[-1][:])))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import numpy as np
N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]
val=np.array(val)
index=np.argsort(val[:,0])
A=val[index,0]
B=val[index,1]

temp=[[0]*N for i in range(T+1)]
for itemp in range(T):
    i=itemp
    if i>=A[0]:
        temp[i][0]=B[0]
    for jtemp in range(N-1):
        j=jtemp+1
        if i>0:
            temp[i][j]=max(temp[i][j],temp[i-1][j])
            
        temp[i][j]=max(temp[i][j],temp[i][j-1])
        if A[j]<T-i:
            temp[i+A[j]][j]=max(temp[i][j-1]+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(temp[i][j-1]+B[j],temp[T][j])
print(max(temp[-1][:])) 

Fixed submission:
# -*- coding: utf-8 -*-

N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]

#import sys
#input = sys.stdin.readline
#val = list(input()) #abc
#val=np.array(val)
#index=np.argsort(val[:,0])
#A=val[index,0].tolist()
#B=val[index,1].tolist()
val.sort()
A=[v[0] for v in val]
B=[v[1] for v in val]

#temp=np.zeros((T+1,N))
#Ts=T*np.ones(N-1)
#jun=np.arange(1,N)
#for itemp in range(T):
#    i=itemp
#    if i>=A[0]:
#        temp[i,0]=B[0]
#    if i>0:
#        temp[i,:]=np.amax([temp[i,:],temp[i-1,:]],0)
#    for jtemp in range(N-1):
#        j=jtemp+1
#        temp[i,j]=max(temp[i,j],temp[i,j-1])
#    jnext=np.amin([Ts,i+A[1:]],0)
#    jnext=[int(s) for s in jnext]
#    temp[jnext,jun]=np.amax([temp[i,:-1]+B[1:],temp[jnext,jun]],0)

temp=[[0]*N for i in range(T+1)]

for itemp in range(T):
    i=itemp
    if i>=A[0]:
        temp[i][0]=B[0]
    for jtemp in range(N-1):
        j=jtemp+1
        jbfo=temp[i][j-1]
        ijnow=temp[i][j]
        
        if i>0:
            temp[i][j]=max(ijnow,temp[i-1][j])
            
        temp[i][j]=max(ijnow,jbfo)
        if A[j]<T-i:
            temp[i+A[j]][j]=max(jbfo+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(jbfo+B[j],temp[T][j])
print(int(max(temp[-1][:])))