Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        A, B = map(int, input().split())
        C.append([B, A])
    # C.sort()

    dp = [[0, 0] for _ in range(T)]
    ans = 0
    for i in range(T):
        for j in range(N):
            if (dp[i][1] >> j) % 2 == 0:
                if i+C[j][1] > T-1:
                    ans = max(ans, dp[i][0] + C[j][0])
                else:
                    if dp[i][0]+C[j][0] > dp[i+C[j][1]][0]:
                        dp[i+C[j][1]][0] = dp[i][0]+C[j][0]
                        dp[i+C[j][1]][1] = (1 << j) | dp[i][1]
        ans = max(ans, dp[i][0])

    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        A, B = map(int, input().split())
        C.append([B, A])

    dp = [[0, set()] for _ in range(T)]
    ans = 0
    for i in range(T):
        for j in range(N):
            if j not in dp[i][1]:
                k = i+C[j][1]
                if k > T-1:
                    ans = max(ans, dp[i][0] + C[j][0])
                else:
                    if dp[i][0]+C[j][0] > dp[k][0]:
                        dp[k][0] = dp[i][0]+C[j][0]
                        dp[k][1] = dp[i][1] | {j}
        ans = max(ans, dp[i][0])

    return ans

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main():

    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        A, B = map(int, input().split())
        C.append([B, A])
    # C.sort()

    dp = [[0, 0] for _ in range(T)]
    ans = 0
    for i in range(T):
        for j in range(N):
            if (dp[i][1] >> j) % 2 == 0:
                if i+C[j][1] > T-1:
                    ans = max(ans, dp[i][0] + C[j][0])
                else:
                    if dp[i][0]+C[j][0] > dp[i+C[j][1]][0]:
                        dp[i+C[j][1]][0] = dp[i][0]+C[j][0]
                        dp[i+C[j][1]][1] = (1 << j) | dp[i][1]

    # print(dp)
    for i in range(T):
        ans = max(ans, dp[i][0])
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        A, B = map(int, input().split())
        C.append([B, A])

    dp = [[0, set()] for _ in range(T)]
    ans = 0
    for i in range(T):
        for j in range(N):
            if j not in dp[i][1]:
                k = i+C[j][1]
                if k > T-1:
                    ans = max(ans, dp[i][0] + C[j][0])
                else:
                    if dp[i][0]+C[j][0] > dp[k][0]:
                        dp[k][0] = dp[i][0]+C[j][0]
                        dp[k][1] = dp[i][1] | {j}
        ans = max(ans, dp[i][0])

    return ans

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main():

    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        A, B = map(int, input().split())
        C.append([B, A])
    C.sort()

    dp = [[0, 0] for _ in range(T)]
    ans = 0
    for i in range(T):
        for j in range(N):
            if (dp[i][1] >> j) % 2 == 0:
                if i+C[j][1] > T-1:
                    ans = max(ans, dp[i][0] + C[j][0])
                else:
                    if dp[i][0]+C[j][0] > dp[i+C[j][1]][0]:
                        dp[i+C[j][1]][0] = dp[i][0]+C[j][0]
                        dp[i+C[j][1]][1] = (1 << j) | dp[i][1]

    for i in range(T):
        ans = max(ans, dp[i][0])
    return ans



if __name__ == '__main__':
    print(main())


Fixed submission:
def main():

    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        A, B = map(int, input().split())
        C.append([B, A])

    dp = [[0, set()] for _ in range(T)]
    ans = 0
    for i in range(T):
        for j in range(N):
            if j not in dp[i][1]:
                k = i+C[j][1]
                if k > T-1:
                    ans = max(ans, dp[i][0] + C[j][0])
                else:
                    if dp[i][0]+C[j][0] > dp[k][0]:
                        dp[k][0] = dp[i][0]+C[j][0]
                        dp[k][1] = dp[i][1] | {j}
        ans = max(ans, dp[i][0])

    return ans

if __name__ == '__main__':
    print(main())