Buggy python submission (verdict: Runtime Error):
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i in range(1, N+1, 1):
        for t in range(T):
            if A[i-1] <= t:
                dp1[i][t] = max(dp1[i-1][t-A[i-1]] + B[i-1], dp1[i-1][t])
            else:
                dp1[i][t] = dp1[i-1][t]
    for i in range(N, 0, -1):
        for t in range(T):
            if A[i-1] <= t:
                dp2[i][t] = max(dp2[i+1][t-A[i-1]] + B[i-1], dp2[i+1][t])
            else:
                dp2[i][t] = dp2[i-1][t]
    v = 0
    for i in range(1, N+1, 1):
        for j in range(T):
            v = max(v, dp1[i-1][j] + dp2[i+1][(T-1) - j] + B[i-1])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Fixed submission:
import itertools


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B


def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i, t in itertools.product(range(N), range(T)):
        u = t - A[i]
        if u >= 0:
            dp1[i+1][t] = max(dp1[i][u] + B[i], dp1[i][t])
        else:
            dp1[i+1][t] = dp1[i][t]
        u = t - A[N-1-i]
        if u >= 0:
            dp2[N-i][t] = max(dp2[N+1-i][u] + B[N-1-i], dp2[N+1-i][t])
        else:
            dp2[N-i][t] = dp2[N+1-i][t]
    v = 0
    for i, t in itertools.product(range(N), range(T)):
        v = max(v, dp1[i][t] + dp2[i+2][(T-1) - t] + B[i])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Buggy python submission (verdict: Runtime Error):
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    a = np.array(A, dtype=np.int32)
    b = np.array(B, dtype=np.int32)
    v = 1.0 * b / a
    order = np.argsort(v)[::-1]
    v = v[order]
    a = a[order]
    b = b[order]
    asum = np.cumsum(a)  # 時間の累積和
    bsum = np.cumsum(b)  # おいしさの累積和
    amax = 0
    bmax = 0
    bmax = 0
    for i in range(N):
        l, r = np.searchsorted(asum, [T, T + a[i]], side='left')
        if r == N:
            bmax = max(bmax, bsum[-1])
        if i == r:
            bmax = max(bmax, bsum[r] - b[i])
        if i < r < N:
            bmax = max(bmax, bsum[r] - b[i])
        if l < i:
            bmax = max(bmax, bsum[l])
    return bmax

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Fixed submission:
import itertools


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B


def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i, t in itertools.product(range(N), range(T)):
        u = t - A[i]
        if u >= 0:
            dp1[i+1][t] = max(dp1[i][u] + B[i], dp1[i][t])
        else:
            dp1[i+1][t] = dp1[i][t]
        u = t - A[N-1-i]
        if u >= 0:
            dp2[N-i][t] = max(dp2[N+1-i][u] + B[N-1-i], dp2[N+1-i][t])
        else:
            dp2[N-i][t] = dp2[N+1-i][t]
    v = 0
    for i, t in itertools.product(range(N), range(T)):
        v = max(v, dp1[i][t] + dp2[i+2][(T-1) - t] + B[i])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))