Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
import sys

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
imax = -1
amax = -1
bmax = -1
for i in range(n):
    _a,_b = _ia()
    ab.append((_a,_b))
    if bmax<0 or (_b>=bmax and _a>ab[imax][0]):
        imax = i
        amax = _a
        bmax = _b
#
dp = [ 0 ] * (t+1)
for i, _ab in enumerate(ab):
    if i==imax: continue
    a,b = _ab
    prev = dp.copy()
    for atot in range(t+1):
        if atot>=a:
            dp[atot] = max(prev[atot],prev[atot-a]+b)
        else:
            dp[atot] = prev[atot]
#
print(max(dp[t-1]+bmax,dp[t]))


Fixed submission:
#!/usr/bin/env python
import sys
from operator import itemgetter

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
for i in range(n): ab.append(_ia())
ab.sort(key=itemgetter(0))
#
bmax= ab[0][0]
dp = [ [0]*(t) for _ in range(n) ]
for i in range(n-1):
    a,b = ab[i]
    
    prev = dp[i]
    dnew = dp[i+1]
    for atot in range(t):
        if atot>=a: dnew[atot] = max(prev[atot],prev[atot-a]+b)
        else: dnew[atot] = prev[atot]
    #
    bmax = max(bmax,prev[-1]+b)
#
print(max(bmax,dp[-1][-1]+ab[-1][1]))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
import sys

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
asum = 1
imax = -1
amax = -1
bmax = -1
for i in range(n):
    _a,_b = _ia()
    ab.append((_a,_b))
    asum += _a
    if bmax<0 or (_b>=bmax and _a>ab[imax][0]):
        imax = i
        amax = _a
        bmax = _b
#
dp = [ 0 ] * (asum)
for i, _ab in enumerate(ab):
    if i==imax: continue
    a,b = _ab
    prev = dp.copy()
    for atot in range(asum):
        if atot>=a:
            dp[atot] = max(prev[atot],prev[atot-a]+b)
        else:
            dp[atot] = prev[atot]
#
if t>asum:
    print(dp[-1]+bmax)
else:
    print(max(dp[t-1]+bmax,dp[t]))


Fixed submission:
#!/usr/bin/env python
import sys
from operator import itemgetter

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
for i in range(n): ab.append(_ia())
ab.sort(key=itemgetter(0))
#
bmax= ab[0][0]
dp = [ [0]*(t) for _ in range(n) ]
for i in range(n-1):
    a,b = ab[i]
    
    prev = dp[i]
    dnew = dp[i+1]
    for atot in range(t):
        if atot>=a: dnew[atot] = max(prev[atot],prev[atot-a]+b)
        else: dnew[atot] = prev[atot]
    #
    bmax = max(bmax,prev[-1]+b)
#
print(max(bmax,dp[-1][-1]+ab[-1][1]))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
import sys

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
asum = 1
imax = -1
amax = -1
bmax = -1
for i in range(n):
    _a,_b = _ia()
    ab.append((_a,_b))
    asum += _a
    if bmax<0 or (_b>=bmax and _a>ab[i-1][0]):
        imax = i
        amax = _a
        bmax = _b
#
del(ab[imax])
asum -= amax
dp = [ 0 ] * (asum)
for a, b in ab:
    prev = dp.copy()
    for atot in range(asum):
        if atot>=a: dp[atot] = max(prev[atot],prev[atot-a]+b)
        else: dp[atot] = prev[atot]
#
if t>asum: print(dp[-1]+bmax)
else: print(max(dp[t-1]+bmax,dp[t]))


Fixed submission:
#!/usr/bin/env python
import sys
from operator import itemgetter

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
for i in range(n): ab.append(_ia())
ab.sort(key=itemgetter(0))
#
bmax= ab[0][0]
dp = [ [0]*(t) for _ in range(n) ]
for i in range(n-1):
    a,b = ab[i]
    
    prev = dp[i]
    dnew = dp[i+1]
    for atot in range(t):
        if atot>=a: dnew[atot] = max(prev[atot],prev[atot-a]+b)
        else: dnew[atot] = prev[atot]
    #
    bmax = max(bmax,prev[-1]+b)
#
print(max(bmax,dp[-1][-1]+ab[-1][1]))