Buggy python submission (verdict: Runtime Error):
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappop(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Fixed submission:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import deque
 
N, M = map(int,input().split())
 
work = [list(map(int,input().split())) for _ in range(N)]
 
wq = deque(sorted(work))
 
paytree = []
 
ans = 0
 
for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        bisect.insort_left(paytree,wq.popleft()[1])
    if len(paytree) > 0:
        ans += paytree.pop(len(paytree) - 1)
 
print(ans)

Fixed submission:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
from collections import deque

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

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

wq = deque(sorted(work))

paytree = deque([])

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        bisect.insort_right(paytree,wq.popleft()[1])
    if len(paytree) > 0:
        ans += paytree.pop()

print(ans)

Fixed submission:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        bisect.insort_right(paytree,wq.popleft()[1])
    if len(paytree) > 0:
        ans += paytree.pop(len(paytree) - 1)

print(ans)

Fixed submission:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        bisect.insort_right(paytree,wq.popleft()[1])
    if len(paytree) > 0:
        ans += paytree.pop(len(paytree) - 1)

print(ans)

Fixed submission:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

class WorkList:
    def __init__(self):
        self.payList = [[] for _ in range(10001)]
        self.payList_sorted = []

    def add(self, a, b):
        if a <= M:
            self.payList[10001 - b].append(a)

    def sort_task(self):
        self.payList_sorted = [deque(sorted(l)) for l in self.payList]

    def get_task(self, deadline):
        for i, q in enumerate(self.payList_sorted):
            if len(q) > 0 and q[0] <= deadline:
                q.popleft()
                return 10001 - i
        return 0


w = WorkList()
for _ in range(N):
    A, B = map(int, input().split())
    w.add(A, B)

w.sort_task()

ans = 0

for d in range(M + 1):
    ans += w.get_task(d)

print(ans)

Fixed submission:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)