Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[0])

DP = [[0] * T for _ in range(N-1)]

for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= AB[0][0]:
				DP[i][j] = AB[0][1]
		else:
			if j >= AB[i][0]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-AB[i][0]] + AB[i][1])
			else:
				DP[i][j] = DP[i-1][j]

ans = 0
tmp = 0

for i in reversed(range(N-1)):
	tmp = max(tmp, AB[i+1][1])
	ans = max(ans, DP[i][T-1] + tmp)

print(ans)

Fixed submission:
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[0])

DP = [[0] * T for _ in range(N-1)]

for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= AB[0][0]:
				DP[i][j] = AB[0][1]
		else:
			if j >= AB[i][0]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-AB[i][0]] + AB[i][1])
			else:
				DP[i][j] = DP[i-1][j]

ans = 0
tmp = 0

for i in reversed(range(N-1)):
	tmp = max(tmp, AB[i+1][1])
	ans = max(ans, DP[i][T-1] + tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, T = map(int, input().split())
I = np.array(read().split(), dtype = np.int32)
A = I[::2]
B = I[1::2]

sort_ind = np.argsort(A)
A = A[sort_ind]
B = B[sort_ind]

DP = np.zeros([N-1, T], dtype = np.int32)
DP[0,A[0]:] = B[0]

for i in range(1, N-1):
	for j in range(T):
		if j - A[i] >= 0:
			DP[i,j] = max(DP[i-1, j], DP[i-1,j-A[i]] + B[i])
		else:
			DP[i,j] = DP[i-1,j]

tmp = 0
for i in reversed(range(N)):
	tmp = max(B[i], tmp)
	B[i] = tmp

C = DP[:,T-1] + B[1:]
print(np.max(C))

Fixed submission:
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[0])

DP = [[0] * T for _ in range(N-1)]

for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= AB[0][0]:
				DP[i][j] = AB[0][1]
		else:
			if j >= AB[i][0]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-AB[i][0]] + AB[i][1])
			else:
				DP[i][j] = DP[i-1][j]

ans = 0
tmp = 0

for i in reversed(range(N-1)):
	tmp = max(tmp, AB[i+1][1])
	ans = max(ans, DP[i][T-1] + tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, T = map(int, input().split())
I = np.array(read().split(), dtype = np.int64)
A = I[::2]
B = I[1::2]

sort_ind = np.argsort(A)
A = A[sort_ind]
B = B[sort_ind]

DP = [[0] * (T) for _ in range(N-1)]
for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= A[0]:
				DP[i][j] = B[0]
		else:
			if j >= A[i]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-A[i]] + B[i])
			else:
				DP[i][j] = DP[i-1][j]




# DP = np.zeros([N-1, T], dtype = np.int64)
# DP[0,A[0]:] = B[0]

# for i in range(1, N-1):
# 	for j in range(T):
# 		if j - A[i] >= 0:
# 			DP[i,j] = max(DP[i-1, j], DP[i-1,j-A[i]] + B[i])
# 		else:
# 			DP[i,j] = DP[i-1,j]

tmp = 0
for i in reversed(range(N)):
	tmp = max(B[i], tmp)
	B[i] = tmp
ans = 0
for i in range(N-1):
	ans = max(ans, DP[i][T-1] + B[i+1])

print(ans)

# C = DP[:,T-1] + B[1:]
# print(np.max(C))

Fixed submission:
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[0])

DP = [[0] * T for _ in range(N-1)]

for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= AB[0][0]:
				DP[i][j] = AB[0][1]
		else:
			if j >= AB[i][0]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-AB[i][0]] + AB[i][1])
			else:
				DP[i][j] = DP[i-1][j]

ans = 0
tmp = 0

for i in reversed(range(N-1)):
	tmp = max(tmp, AB[i+1][1])
	ans = max(ans, DP[i][T-1] + tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, T = map(int, input().split())
I = np.array(read().split(), dtype = np.int64)
A = I[::2]
B = I[1::2]

sort_ind = np.argsort(A)
A = A[sort_ind]
B = B[sort_ind]

DP = np.zeros([N-1, T], dtype = np.int64)
DP[0,A[0]:] = B[0]

for i in range(1, N-1):
	for j in range(T):
		if j - A[i] >= 0:
			DP[i,j] = max(DP[i-1, j], DP[i-1,j-A[i]] + B[i])
		else:
			DP[i,j] = DP[i-1,j]

tmp = 0
for i in reversed(range(N)):
	tmp = max(B[i], tmp)
	B[i] = tmp

C = DP[:,T-1] + B[1:]
print(np.max(C))

Fixed submission:
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[0])

DP = [[0] * T for _ in range(N-1)]

for i in range(N-1):
	for j in range(T):
		if i == 0:
			if j >= AB[0][0]:
				DP[i][j] = AB[0][1]
		else:
			if j >= AB[i][0]:
				DP[i][j] = max(DP[i-1][j], DP[i-1][j-AB[i][0]] + AB[i][1])
			else:
				DP[i][j] = DP[i-1][j]

ans = 0
tmp = 0

for i in reversed(range(N-1)):
	tmp = max(tmp, AB[i+1][1])
	ans = max(ans, DP[i][T-1] + tmp)

print(ans)