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
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(q)
heapq.heapify(s)
for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            
            p=heapq.heappop(s)
            if p[0]+k<=m:
                
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            
            p=heapq.heappop(q)
            ans+=-p
print(ans)




import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            
            p=heapq.heappop(s)
            if p[0]+k<=m:
                
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            
            p=heapq.heappop(q)
            ans+=-p
print(ans)




import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(s)
for k in range(m-2,-1,-1):
    if s!=[]:
        
        p=heapq.heappop(s)
        if p[0]+k<=m:
            
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        
        p=heapq.heappop(q)
        ans+=-p
print(ans)


import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(s)
heapq.heapify(q)
for k in range(m-1,-1,-1):
    if s!=[]:
        
        p=heapq.heappop(s)
        if p[0]+k<=m:
            
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        
        p=heapq.heappop(q)
        ans+=-p
print(ans)


import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(s)
for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            
            p=heapq.heappop(s)
            if p[0]+k<=m:
                
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            
            p=heapq.heappop(q)
            ans+=-p
print(ans)




import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(s)
for k in range(m,-1,-1):
    while True:
        if s!=[]:
            
            p=heapq.heappop(s)
            if p[0]+k<=m:
                
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            
            p=heapq.heappop(q)
            ans+=-p
print(ans)




n,m=map(int, input().split())
s=[[int(j) for j in input().split()] for i in range(n)]
ans=0
s.sort(reverse=True,key=lambda x:x[1])
for k in range(m):
    for i in range(n):
        if s[i][0]+k>m:
            print(s[i])
            s[i:i+1]=[]
            n=n-1
    if s==[]:
        break
    else:
        ans+=s[0][1]
        print(s[0])
        s[0:1]=[]
        n=n-1
print(ans)


import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(s)
heapq.heapify(q)
for k in range(m,-1,-1):
    if s!=[]:
        
        p=heapq.heappop(s)
        if p[0]+k<=m:
            
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        
        p=heapq.heappop(q)
        ans+=-p
print(ans)


import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

heapq.heapify(s)
heapq.heapify(q)
for k in range(m-2,-1,-1):
    if s!=[]:
        
        p=heapq.heappop(s)
        if p[0]+k<=m:
            
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        
        p=heapq.heappop(q)
        ans+=-p
print(ans)


import heapq as hq
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a.sort()
for i in range(n):
    a[i][1]*=-1
b=[]
hq.heapify(b)
ans,i=0,0
for k in range(m-1,-1,-1):
    while i<n and a[i][0]+k<=m:
        hq.heappush(b,a[i][1])
        i+=1
    if b:
        ans-=hq.heappop(b)
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted