Buggy python submission (verdict: Time Limit Exceeded):
n, t = map(int, input().split())
lst = []
for i in range(n):
    lsti = list(map(int, input().split()))
    lst.append(lsti)

lst.sort(key=lambda x: x[0])
a, b = [], []
for i in range(n):
    lsti = lst[i]
    a.append(lsti[0])
    b.append(lsti[1])

# DPテーブルの作成
dp = [[-1 for i in range(t)] for j in range(n+1)]
for i in range(t):
    dp[0][i] = 0

# DPテーブルの更新
for i in range(n):
    for j in range(t):
        if j >= a[i]:
            dp[i+1][j] = max(dp[i][j-a[i]]+b[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

# 答え(最大となる合計価値)
kouho = []
for i in range(n):
    kouho.append(dp[i][t-1]+b[i])
kouho.append(dp[n][t-1])
print(max(kouho))

Fixed submission:
n, t = map(int, input().split())
lst = []
for i in range(n):
    lsti = list(map(int, input().split()))
    lst.append(lsti)

lst.sort(key=lambda x: x[0])
a, b = [], []
for i in range(n):
    lsti = lst[i]
    a.append(lsti[0])
    b.append(lsti[1])

# DPテーブルの作成
dp = [[-1 for i in range(t)] for j in range(n+1)]
for i in range(t):
    dp[0][i] = 0

# DPテーブルの更新
for i in range(n):
    for j in range(t):
        if j >= a[i]:
            dp[i+1][j] = max(dp[i][j-a[i]]+b[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

# 答え(最大となる合計価値)
kouho = []
for i in range(n):
    kouho.append(dp[i][t-1]+b[i])
kouho.append(dp[n][t-1])
print(max(kouho))

Buggy python submission (verdict: Runtime Error):
n, t = map(int, input().split())

class Item:

    def __init__(self, value, weight):
        self.value = value
        self.weight = weight
        self.density = value / weight

    def __str__(self):
        return f'weight = {self.weight}, value = {self.value}'


class Knapsack:

    def __init__(self, weight_limit):
        self.weight_limit = weight_limit
        self.weight = 0
        self.value = 0
        self.items = []

    def add(self, item):
        if self.weight + item.weight <= self.weight_limit:
            self.weight += item.weight
            self.value += item.value
            self.items.append(item)

    def show(self):
        return self.value


def buildItems():
    lst = []
    weights = []
    values = []
    for i in range(n):
        lsti = list(map(int, input().split()))
        lst.append(lsti)
    lst.sort(key= lambda x: x[1])
    saidai = lst.pop()[1]
    for i in range(n-1):
        weights.append(lst[i][0])
        values.append(lst[i][0])
    return [Item(*params) for params in zip(values, weights)], saidai


def testGreedys(weight_limit=t-1):
    def packing(greedy):
        knapsack = Knapsack(weight_limit)
        for item in sorted(items, key=greedy, reverse=True):
            knapsack.add(item)
        return knapsack.show()

    items, saidai = buildItems()
    ans1 = packing(lambda item: item.value)    # 高価値優先
    ans2 = packing(lambda item: -item.weight)  # 軽量優先
    ans3 = packing(lambda item: item.density)  # 高密度優先
    print(max(ans1, ans2, ans3)+saidai)

if __name__ == '__main__':
    testGreedys()

Fixed submission:
n, t = map(int, input().split())
lst = []
for i in range(n):
    lsti = list(map(int, input().split()))
    lst.append(lsti)

lst.sort(key=lambda x: x[0])
a, b = [], []
for i in range(n):
    lsti = lst[i]
    a.append(lsti[0])
    b.append(lsti[1])

# DPテーブルの作成
dp = [[-1 for i in range(t)] for j in range(n+1)]
for i in range(t):
    dp[0][i] = 0

# DPテーブルの更新
for i in range(n):
    for j in range(t):
        if j >= a[i]:
            dp[i+1][j] = max(dp[i][j-a[i]]+b[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

# 答え(最大となる合計価値)
kouho = []
for i in range(n):
    kouho.append(dp[i][t-1]+b[i])
kouho.append(dp[n][t-1])
print(max(kouho))