Buggy python submission (verdict: Runtime Error):
import heapq
 
 
 
n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))


t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m+1):
    while t_r_list[l][0] == j:
        heapq.heappush(que, -t_r_list[l][1])
        l += 1
        if l >= n:
            break
        
 
    if que:
        total -= heapq.heappop(que)
      
      
print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))

t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m + 1):
    while True:
        if l == n:
            break
        if t_r_list[l][0] != j:
            break
        heapq.heappush(que, -t_r_list[l][1])
        l += 1

    if que:
        total -= heapq.heappop(que)


print(total)

Buggy python submission (verdict: Runtime Error):
import heapq
 
 
 
n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))


t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m+1):
    while j < m and t_r_list[l][0] == j:
        heapq.heappush(que, -t_r_list[l][1])
        l += 1
        if l >= n:
            break
        
 
    if que:
        total -= heapq.heappop(que)
      
      
print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))

t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m + 1):
    while True:
        if l == n:
            break
        if t_r_list[l][0] != j:
            break
        heapq.heappush(que, -t_r_list[l][1])
        l += 1

    if que:
        total -= heapq.heappop(que)


print(total)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import heapq
 
 
 
n, m = map(int, input().split())
m_dict = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    m_dict[a] = m_dict[a] + [b]


job_que = []
    
    
total = 0
for j in range(1, m+1):
    for k in m_dict[j]:
        heapq.heappush(job_que, -k)
 
 
    if job_que:
        total -= heapq.heappop(job_que)
        
    
            
print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))

t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m + 1):
    while True:
        if l == n:
            break
        if t_r_list[l][0] != j:
            break
        heapq.heappush(que, -t_r_list[l][1])
        l += 1

    if que:
        total -= heapq.heappop(que)


print(total)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from queue import PriorityQueue
 
 

n, m = map(int, input().split())
m_dict = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    m_dict[a] = m_dict[a] + [b]
    

job_que = PriorityQueue()
    
    
total = 0
for j in range(1, m+1):
    for k in m_dict[j]:
        job_que.put(-k)
 
 
    if job_que:
        total -= job_que.get()
        
    
            
print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))

t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m + 1):
    while True:
        if l == n:
            break
        if t_r_list[l][0] != j:
            break
        heapq.heappush(que, -t_r_list[l][1])
        l += 1

    if que:
        total -= heapq.heappop(que)


print(total)

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


n, m = map(int, input().split())
m_dict = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    m_dict[a] = m_dict[a] + [b]
    

    
job_que = []
total = 0
for j in range(1, m+1):
    job_que.extend(m_dict[j])
 
 
    if job_que:
        job_que.sort()
        total += job_que.pop()
        
    
            
print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))

t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m + 1):
    while True:
        if l == n:
            break
        if t_r_list[l][0] != j:
            break
        heapq.heappush(que, -t_r_list[l][1])
        l += 1

    if que:
        total -= heapq.heappop(que)


print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())


time_reward_tuple = []


for i in range(n):
    a, b = map(int, input().split())
    time_reward_tuple.append((a, b))

    
job_que = []


total = 0


for j in range(1, m+1):
    for l in [r for t, r in time_reward_tuple if t==j]:
        job_que.append(l)


    if job_que:
        job_que.sort()
        total += job_que.pop()
        
    
    
print(total)

Fixed submission:
import heapq

n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))

t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m + 1):
    while True:
        if l == n:
            break
        if t_r_list[l][0] != j:
            break
        heapq.heappush(que, -t_r_list[l][1])
        l += 1

    if que:
        total -= heapq.heappop(que)


print(total)