Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
        elif self.award==other.award and self.date<other.date:
            return True
        elif self.award==other.award and self.date=other.date and self.name>other.name:
            return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
        elif self.award==other.award and self.date>other.date:
            return True
        elif self.award==other.award and self.date=other.date and self.name<other.name:
            return False
        else:
            return False

jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            break
        
        
print(ans)
    
    

n,limit=[int(i) for i in input().split()]
baitolist=[[int(i) for i in input().split()] for j in range(n)]
baitodict={}
for i in range(1,limit+1):
    baitodict[str(i)]=[]
for baito in baitolist:
    if int(day)<=limit:
        day=str(baito[0])
        money=baito[1]
        baitodict[day].append(money)
        baitodict[day].sort()


sumnum=0
for i in range(1,limit+1):
    maxindex=""
    maxmoney=0
    for j in range(1,i+1):
        if baitodict[str(j)]!=[]:
            a=baitodict[str(j)][-1]
            if maxmoney<a:
                maxmoney=a
                maxindex=str(j)
    if maxindex!="":
        baitodict[maxindex].pop()
    sumnum+=maxmoney
#     print(sumnum)
print(sumnum)            

import heapq
from collections import deque

class job:
    def __init__(self,date,award):
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
#         elif self.award==other.award and self.date>other.date:
#             return True
#         elif self.award==other.award and self.date==other.date and self.name>other.name:
#             return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
#         elif self.date==other.date and self.award>other.award:
#             return True
#         elif self.award==other.award and self.date==other.date and self.name<other.name:
#             return False
        else:
            return False
    def __eq__(self,other):
        if self.award==other.award:
            return True
        else:
            return False

jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(info)
jobs.sort()

jobdeque=deque()
for i in jobs:
    jobdeque.append(i)
    
ans=0
heap=[]
heapq.heapify(heap)
for i in range(m):
    while jobdeque:
        a=jobdeque.popleft()
        if a[0]==i+1:
            heapq.heappush(heap,job(a[0],a[1]))
        else:
            jobdeque.appendleft(a)
            break
    if heap:
        b=heapq.heappop(heap)
        ans+=b.award
                          
print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted