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):
def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())


ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**8
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        
        heapq.heappush(koho,-ab[i][1])
        i+=1
    

    tmp=heapq.heappop(koho)
    #print(tmp)
    res+=(-tmp)
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

#print(do)
'''
3 6
4 5
4 3
6 4

'''

def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())


ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**8
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        
        heapq.heappush(koho,-ab[i][1])
        i+=1
    

    try:
        tmp=heapq.heappop(koho)
    except:
        break

    #print(tmp)
    res+=(-tmp)
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))


def acinput():
    return list(map(int, input().split(" ")))

import numpy as np

import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())


ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**8
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        
        heapq.heappush(koho,-ab[i][1])
        i+=1
    

    tmp=heapq.heappop(koho)
    #print(tmp)
    res+=(-tmp)
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

#print(do)
'''
3 6
4 5
4 3
6 4

'''

def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())


ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**10
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        
        heapq.heappush(koho,-ab[i][1])
        i+=1

    try:
        tmp=heapq.heappop(koho)
        res+=(-tmp)
    except:
        break

    
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

#print(do)
'''
3 6
4 5
4 3
6 4

'''

def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())


ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**8
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        
        heapq.heappush(koho,-ab[i][1])
        i+=1
    

    try:
        tmp=heapq.heappop(koho)
        res+=(-tmp)
    except:
        break

    #print(tmp)
    
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

#print(do)
'''
3 6
4 5
4 3
6 4

'''

def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())


ab=sorted(ab,key=lambda x:x[0])
#print(ab)

res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    #print(nowdate)
    i=k
    while True:
        if i>=len(ab):
            k=10**10
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        
        heapq.heappush(koho,-ab[i][1])
        i+=1
    
    try:
        tmp=heapq.heappop(koho)
        res+=(-tmp)
    except:
        pass

    
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))



Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted