Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

N, M = map(int, input().split())

jobs = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

ans = 0
heap = []
for day in range(1,M+1):
	for i in jobs:
		ccc = 0
		if i[0] == day:
			heappush(heap, -i[1])
			ccc += 1
		elif i[0] > day:
			del(jobs[0:ccc])
			break
    
	if len(heap) > 0:
		ans += -heappop(heap)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

N, M = map(int, input().split())

jobs = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

ans = 0
heap = []
for day in range(1,M+1):
	for i in jobs:		
		if i[0] == day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) > 0:
		ans += -heappop(heap)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, M = map(int, input().split())

jobs = [list(map(int, input().split())) for _ in range(N)]

jobs.sort(key = lambda x: x[0])

ans = 0
heap = []
for day in range(1,M+1):
	for i in jobs:		
		if i[0] == day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) != 0:
		ans += -heappop(heap)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, M = map(int, input().split())

list = [list(map(int, input().split())) for _ in range(N)]


list.sort(key = lambda x: x[0])

ans = 0
heap = []
for day in range(1,M+1):
	for i in list:		
		if i[0] == day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) != 0:
		ans += -heappop(heap)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

N, M = map(int, input().split())

list = [list(map(int, input().split())) for _ in range(N)]


list.sort(key = lambda x: x[0])

ans = 0
heap = []
for day in range(1,M+1):
	for i in list:		
		if i[0] == day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) > 0:
		ans += -heappop(heap)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

N, M = map(int, input().split())
list = []
for _ in range(N):
	a, b = map(int, input().split())
	if a <= M:
		list.append([a, b])

list.sort()

ans = 0
heap = []
for day in range(1,M+1):
	for i in list:		
		if i[0] == day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) != 0:
		ans += -heappop(heap)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

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

N, M = map(int, input().split())

l = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    if tmp[0] <= M:
        l.append(tmp)

l.sort()
ans = 0
a = []
for i in range(1, M+1):
    for j in l:
        if j[0] == i:
            heapq.heappush(a, -j[1])
        elif j[0] > i:
            break
    if len(a) != 0:
        ans -= heapq.heappop(a)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

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

N, M = map(int, input().split())
list = [list(map(int, input().split())) for i in range(N)]

ans = 0
a = []
for i in range(1, M+1):
    for j in list:
      if j[0] == i:
        heapq.heappush(a, -j[1])       
    if len(a) != 0:
        ans += heapq.heappop(a)*(-1)

print(ans)

Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]

ans = 0
l2 = []
for i in range(1, M+1):
    tmp = [j[1] for j in list if j[0] == i]
    l2.extend(tmp)
    l2.sort(reverse=True)
    if len(l2) != 0:
        ans += l2.pop(0)

print(ans)


Fixed submission:
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)