Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
N,M = map(int,input().split())
ls = []
for n in range(N):
  ls.append(list(map(int,input().split())))
ls = np.array(ls)
idx = np.argsort(ls[:,1])[::-1]
#print (ls[idx])
days = list(range(1,M+1))
days = {k: 0 for k in days}
#print (days)
sum = 0
skip_d = -1
flag = False
for work in ls[idx]:
  d = work[0]
  if d==skip_d:
    pass
  else:
    while(d<=M):
      if d in days:
        sum+=work[1]
        days.pop(d)
        d=M+1
        skip_d = -1
        flag = True
      else:
        d+=1
    if not flag:
      skip_d = work[0]
      flag = False
print (sum)
  
    


Fixed submission:
import heapq
N,M = map(int,input().split())
ls = []
h = []
ans = 0
for n in range(N):
    ls.append(list(map(int,input().split())))
ls = sorted(ls,key=lambda ls:ls[0],reverse=False)
n = 0
for m in range(1,M+1):
    #print (m)
    while(n<N and ls[n][0]<=m ):
        heapq.heappush(h, -ls[n][1])
        n+=1
    if len(h)>0:
        ans -= heapq.heappop(h)
        # print (m,ans)
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
N,M = map(int,input().split())
ls = []
for n in range(N):
  ls.append(list(map(int,input().split())))
ls = np.array(ls)
idx = np.argsort(ls[:,1])[::-1]
#print (ls[idx])
days = list(range(1,M+1))
days = {k: 0 for k in days}
#print (days)
sum = 0
skip_d = -1
for work in ls[idx]:
  d = work[0]
  if d==skip_d:
    pass
  else:
    while(d<=M):
      if d in days:
        sum+=work[1]
        days.pop(d)
        d=M+1
        skip_d = -1
      else:
        d+=1
        skip_d = work[0]
print (sum)
  
    


Fixed submission:
import heapq
N,M = map(int,input().split())
ls = []
h = []
ans = 0
for n in range(N):
    ls.append(list(map(int,input().split())))
ls = sorted(ls,key=lambda ls:ls[0],reverse=False)
n = 0
for m in range(1,M+1):
    #print (m)
    while(n<N and ls[n][0]<=m ):
        heapq.heappush(h, -ls[n][1])
        n+=1
    if len(h)>0:
        ans -= heapq.heappop(h)
        # print (m,ans)
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
ls = []
for n in range(N):
  ls.append(list(map(int,input().split())))
ls = sorted(ls, key=lambda x:x[1],reverse=True)

days = {i:0 for i in range(1,M+1)}
sum = 0
max_d = max(days.keys())
for work in ls:
  d = work[0]
  while(d<=max_d):
    if d in days:
      sum+=work[1]
      days.pop(d)
      key = days.keys()
      if len(key)==0:
        max_d = 0
      else:
        max_d = max(days.keys())
      d=M+1
    else:
      d+=1
print (sum)
  
    

Fixed submission:
import heapq
N,M = map(int,input().split())
ls = []
h = []
ans = 0
for n in range(N):
    ls.append(list(map(int,input().split())))
ls = sorted(ls,key=lambda ls:ls[0],reverse=False)
n = 0
for m in range(1,M+1):
    #print (m)
    while(n<N and ls[n][0]<=m ):
        heapq.heappush(h, -ls[n][1])
        n+=1
    if len(h)>0:
        ans -= heapq.heappop(h)
        # print (m,ans)
print (ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
N,M = map(int,input().split())
ls = []
for n in range(N):
  ls.append(list(map(int,input().split())))
ls = np.array(ls)
idx = np.argsort(ls[:,1])[::-1]
#print (ls[idx])
days = list(range(1,M+1))
days = {k: 0 for k in days}
#print (days)
sum = 0
for work in ls[idx]:
  d = work[0]
  while(d<=M):
    if d in days:
      sum+=work[1]
      days.pop(d)
      d=M+1
    else:
      d+=1
print (sum)
  
    

Fixed submission:
import heapq
N,M = map(int,input().split())
ls = []
h = []
ans = 0
for n in range(N):
    ls.append(list(map(int,input().split())))
ls = sorted(ls,key=lambda ls:ls[0],reverse=False)
n = 0
for m in range(1,M+1):
    #print (m)
    while(n<N and ls[n][0]<=m ):
        heapq.heappush(h, -ls[n][1])
        n+=1
    if len(h)>0:
        ans -= heapq.heappop(h)
        # print (m,ans)
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
N,M = map(int,input().split())
ls = []
for n in range(N):
  ls.append(list(map(int,input().split())))
ls = np.array(ls)
idx = np.argsort(ls[:,1])[::-1]
#print (ls[idx])
days = list(range(1,M+1))
days = {k: 0 for k in days}
#print (days)
sum = 0
for work in ls[idx]:
  d = work[0]
  while(d<=M):
    if d in days:
      sum+=work[1]
      days.pop(d)
      d=M+1
    else:
      d+=1
print (sum)
  
    

Fixed submission:
import heapq
N,M = map(int,input().split())
ls = []
h = []
ans = 0
for n in range(N):
    ls.append(list(map(int,input().split())))
ls = sorted(ls,key=lambda ls:ls[0],reverse=False)
n = 0
for m in range(1,M+1):
    #print (m)
    while(n<N and ls[n][0]<=m ):
        heapq.heappush(h, -ls[n][1])
        n+=1
    if len(h)>0:
        ans -= heapq.heappop(h)
        # print (m,ans)
print (ans)