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() # 食べるのが早い順にソート

# ナップザック問題に落とし込む
dp = [[0 for i in range(t+1)]for j in range(n+1)]

for i in range(n):
    ti,vi = ab[i]
    for j in range(t+1):
        # 食べたほうがよい(t秒以内かつ満足度が上がるならば)
        if j + ti <= t:
            dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
        # 食べなかった場合の最高値を更新
        dp[i+1][j] = max(dp[i][j],dp[i+1][j])

ma = 0

for i in range(n):
    # 最後にi番目の皿を食べることができる
    ma = max(ma,dp[i][t-1]+ab[i][1])

print(ma)

Fixed submission:
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
# 最後に入れる商品は、残り容量１の時に入れるとしてしまってよい
for i, (wi, vi) in enumerate(items):
    ans = max(ans, dp[i][W - 1] + vi)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,t = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
dp = [[0 for i in range(t+1)]for j in range(n+1)]
for i in range(n):
    ti,vi = ab[i]
    for j in range(t+1):
        if j + ti <= t:
            dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
        dp[i+1][j] = max(dp[i][j],dp[i+1][j])
ma = 0
for i in range(n):
    ma = max(ma,dp[i][t-1]+ab[i][1])
print(ma)

Fixed submission:
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
# 最後に入れる商品は、残り容量１の時に入れるとしてしまってよい
for i, (wi, vi) in enumerate(items):
    ans = max(ans, dp[i][W - 1] + vi)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,t = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
dp = np.array([[0 for i in range(t+1)]for j in range(n+1)])
for i in range(n):
    ti,vi = ab[i]
    for j in range(t+1):
        if j + ti <= t:
            dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
        dp[i+1][j] = max(dp[i][j],dp[i+1][j])
ma = 0
for i in range(n):
    ma = max(ma,dp[i][t-1]+ab[i][1])
print(ma)

Fixed submission:
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
# 最後に入れる商品は、残り容量１の時に入れるとしてしまってよい
for i, (wi, vi) in enumerate(items):
    ans = max(ans, dp[i][W - 1] + vi)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,t = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
dp = [[0 for i in range(t+1)]for j in range(n+1)]
for i in range(n):
    ti,vi = ab[i]
    for j in range(t+1):
        if j + ti <= t:
            dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
        dp[i+1][j] = max(dp[i][j],dp[i+1][j])
ma = 0
for i in range(n):
    ma = max(ma,dp[i][t-1]+ab[i][1])
print(ma)

Fixed submission:
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
# 最後に入れる商品は、残り容量１の時に入れるとしてしまってよい
for i, (wi, vi) in enumerate(items):
    ans = max(ans, dp[i][W - 1] + vi)

print(ans)