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

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
for i in range(m):
    bar = True
    while bar:
        if len(li) == 0:
            break
        if i >= li[0][0] - 1:
            price = li.pop(0)
            heapq.heappush(heap,-price[1])
        else:
            bar = False
    try:
        ans += -heapq.heappop(heap)
    except IndexError:
        ans += 0
 
print(ans)

Fixed submission:
import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)

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

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
for i in range(m):
    bar = True
    while bar:
        if len(li) == 0:
            break
        if i >= li[0][0] - 1:
            price = li.pop(0)
            heapq.heappush(heap,-price[1])
        else:
            bar = False
    try:
        ans += -heapq.heappop(heap)
    except IndexError:
        ans += 0
 
print(ans)

Fixed submission:
import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
jobs.sort(key = lambda x:(x[1],x[0]))
jobs.reverse()
score = 0
for i in range(b):
  for j in range(len(jobs)):
    job = jobs[j]
    if job[0] <= i + 1:
      score += job[1]
      jobs.remove(job)
      break;
print(score)

Fixed submission:
import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
jobs.sort(key = lambda x:(x[1],x[0]))
score = 0
for i in range(b):
  for j in range(len(jobs)):
    job = jobs[len(jobs) - j - 1]
    if job[0] <= i + 1:
      score += job[1]
      jobs.remove(job)
      break;
print(score)

Fixed submission:
import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
score = 0
for i in range(b):
  max_now = 0
  deli = []
  for j in range(len(jobs)):
    job = jobs[j]
    if job[0] <= i + 1:
      if max_now < job[1]:
        max_now = job[1]
        deli = job
  score += max_now 
  if deli != []:
    jobs.remove(deli)
print(score)

Fixed submission:
import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)