Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(x) for x in input().split()]
AB_list = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: int(x[0]))
h = []
ans = 0
for i in range(1, M+1):
    while(len(AB_list) > 0 and AB_list[0][0] <= i):
        tmp = AB_list.pop(0)
        h.append(tmp[1])
    if (len(h)):
        tmp = max(h)
        h.pop(h.index(tmp))
        ans += tmp
print(ans)


Fixed submission:
import heapq
N, M = [int(x) for x in input().split()]
AB_list = [[] for _ in range(M)]
for _ in range(N):
    A, B = list(map(int, input().split()))
    if (A > M): continue
    AB_list[A-1].append(B)
h = []
ans = 0
for i in range(M):
    for B in AB_list[i]:
        heapq.heappush(h, -B)
    # print(AB_list, h)
    if (len(h)):
        ans += -heapq.heappop(h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = [int(x) for x in input().split()]
AB_list = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: int(x[0]))
h = []
ans = 0
for i in range(1, M+1):
    while(len(AB_list) > 0 and AB_list[0][0] <= i):
        tmp = AB_list.pop(0)
        heapq.heappush(h, -1 * tmp[1])
    # print(AB_list, h)
    if (len(h)):
        ans += -1 * heapq.heappop(h)
print(ans)


Fixed submission:
import heapq
N, M = [int(x) for x in input().split()]
AB_list = [[] for _ in range(M)]
for _ in range(N):
    A, B = list(map(int, input().split()))
    if (A > M): continue
    AB_list[A-1].append(B)
h = []
ans = 0
for i in range(M):
    for B in AB_list[i]:
        heapq.heappush(h, -B)
    # print(AB_list, h)
    if (len(h)):
        ans += -heapq.heappop(h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = [int(x) for x in input().split()]
AB_list = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: int(x[0]))
h = []
ans = 0
for i in range(1, M+1):
    lst = AB_list[:]
    for A, B in lst:
        if (A <= i):
            tmp = AB_list.pop(0)
            heapq.heappush(h, -1 * tmp[1])
        else: break
    # print(AB_list, h)
    if (len(h)):
        ans += -1 * heapq.heappop(h)
print(ans)



Fixed submission:
import heapq
N, M = [int(x) for x in input().split()]
AB_list = [[] for _ in range(M)]
for _ in range(N):
    A, B = list(map(int, input().split()))
    if (A > M): continue
    AB_list[A-1].append(B)
h = []
ans = 0
for i in range(M):
    for B in AB_list[i]:
        heapq.heappush(h, -B)
    # print(AB_list, h)
    if (len(h)):
        ans += -heapq.heappop(h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = [int(x) for x in input().split()]
AB_list = sorted([input().split() for _ in range(N)], key=lambda x: int(x[0]))
h = []
ans = 0
for i in range(1, M+1):
    lst = AB_list[:]
    for A, B in lst:
        if (int(A) <= i):
            tmp = AB_list.pop(0)
            heapq.heappush(h, -1 * int(tmp[1]))
        else: break
    # print(AB_list, h)
    if (len(h)):
        ans += -1 * heapq.heappop(h)
print(ans)


Fixed submission:
import heapq
N, M = [int(x) for x in input().split()]
AB_list = [[] for _ in range(M)]
for _ in range(N):
    A, B = list(map(int, input().split()))
    if (A > M): continue
    AB_list[A-1].append(B)
h = []
ans = 0
for i in range(M):
    for B in AB_list[i]:
        heapq.heappush(h, -B)
    # print(AB_list, h)
    if (len(h)):
        ans += -heapq.heappop(h)
print(ans)