Problem:


Score : 400 points

Problem Statement

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.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i \leq 10^5

1 \leq B_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the maximum total reward that you can earn no later than M days from today.

Sample Input 1

3 4
4 3
4 1
2 2

Sample Output 1

5

You can earn the total reward of 5 by taking the jobs as follows:

Take and complete the first job today. You will earn the reward of 3 after four days from today.

Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.

Sample Input 2

5 3
1 2
1 3
1 4
2 1
2 3

Sample Output 2

10

Sample Input 3

1 1
2 1

Sample Output 3

0



Sample input:
3 4
4 3
4 1
2 2


Sample output:
5

Submission status: Wrong Answer

Solution code:
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
from collections import defaultdict
n,m = I0()
m+=1
job = list()

for i in range(n):
    a,b = I0()
    job.append([b,a])

job = sorted(job, reverse=True)


day = 1
res = 0

for i in range(n):
    b,a = job[i]
    if day+a<=m:
        res+=b
        day+=1
print(res)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
ansList = []
newList = []
jobList = [[] for _ in range(100001)]
for i in range(N):
    A, B = map(int, input().split())
    jobList[A-1].append(B)

for i in range(M):
    num = M - i
    jobList[i].sort(reverse=True)
    try:
        newList = jobList[i][:num]
        ansList = ansList + newList
    except IndexError:
        newList = jobList[i]
        ansList = ansList + newList

ansList.sort(reverse=True)
ansList = ansList[:M]
print(sum(ansList))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from heapq import heappush, heappop
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))
baitos = [[-baito[1], baito[0]] for baito in baitos]
max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    #kuwaeru
    for baito_index in range(len(baitos)):
        if baitos[baito_index][1] <= nokori:
            heappush(available_works, baitos[baito_index])
        else:
            baitos = baitos[baito_index:]
            break

    #itibanniiyatu
    if len(available_works) > 0:
        max += (heappop(available_works))[0]

print(-max)

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    #kuwaeru
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            heapq.heappush(available_works, baitos[baito_index])
        else:
            baitos = baitos[baito_index:]
            break
    #itibanniiyatu
    if len(available_works) > 0:
        max += available_works[-1][1]
        available_works.pop(-1)

print(max)

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    #kuwaeru
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            heapq.heappush(available_works, baitos[baito_index])
        else:
            baitos = baitos[baito_index:]
            break

    #itibanniiyatu
    if len(available_works) > 0:
        max += available_works[-1][1]
        available_works.pop(-1)

print(max)

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    #kuwaeru
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            heapq.heappush(available_works, baitos[baito_index])
        else:
            baitos = baitos[baito_index:]
            break

    #itibanniiyatu
    if len(available_works) > 0:
        max += available_works[-1][1]

print(max)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    #kuwaeru
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            available_works.append(baitos[baito_index])
        else:
            baitos = baitos[baito_index:]
            break

    #itibanniiyatu
    max_now = 0
    max_index = None

    for work_index in range(len(available_works)):
        if available_works[work_index][1] >= max_now:
            print("oke")
            max_index = work_index
            max_now = available_works[max_index][1]

    if max_index is not None:
        max += max_now
        available_works.pop(max_index)
        max_index = None

print(max)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    #kuwaeru
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            available_works.append(baitos[baito_index])
        else:
            baitos = baitos[baito_index+1:]
            break
    #itibanniiyatu
    max_now = 0
    max_index = None

    for work_index in range(len(available_works)):
        if available_works[work_index][1] >= max_now:
            max_index = work_index
            max_now = available_works[max_index][1]

    if max_index:
        max += max_now
        available_works.pop(max_index)

print(max)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(reverse=True)
sortAB = sorted(AB,key= lambda x: x[1],reverse = True)
cnt = 0
ans = 0
print(sortAB)
for i in range(N):
  a,b = sortAB[i]
  if cnt+a<=M:
    cnt= cnt+1
    ans = ans+b
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
sortAB = sorted(AB,key= lambda x: x[1],reverse = True)
sortAB.sort(reverse=True)
cnt = 0
ans = 0
print(sortAB)
for i in range(N):
  a,b = sortAB[i]
  if cnt+a<=M:
    cnt= cnt+1
    ans = ans+b
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(reverse=True)
sortAB = sorted(AB,key= lambda x: x[1],reverse = True)
cnt = 0
ans = 0
#print(sortAB)
for i in range(N):
  a,b = sortAB[i]
  if cnt+a<=M:
    cnt= cnt+1
    ans = ans+b
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
A = []

for i in range(N):
    a,b = list(map(int,input().split()))
    A.append([a,b])
A.sort()

ans = 0

for i in range(1,M+1):
    
    temp_max = 0
    arg = 0
    
    for j in range(N):
        
        if A[j][0] > i:
            break
        
        if A[j][1] > temp_max:
            temp_max = A[j][1]
            arg = j        
    
    ans += temp_max
    A[arg][1] = -1
    
print(ans)

Submission status: Wrong Answer

Solution code:

import heapq
from collections import defaultdict

N, M = map(int, input().split())

a_b_dict = defaultdict(list)
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    a_b_dict[a].append(b)


result = []
h = []
num_days = 0
for i in range(1, 1+M):
    for b in a_b_dict.get(i, []):
        heapq.heappush(h, -b)

    while len(result) < i:
        if len(h) > 0:
            result.append(-1*heapq.heappop(h))
        else:
            break

print(sum(result))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())

a_b_list = []
for _ in range(N):
    a_b_list.append(tuple(map(int, input().split())))

a_b_list = sorted(a_b_list, key=lambda x: (x[1], x[0]), reverse=True)
reward = 0
num_day = 0
for a, b in a_b_list:
    if num_day + a <= M:
        reward += b
        num_day += 1
    if num_day == M:
        break
print(reward)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

s = sys.stdin.readlines()
n,m = map(int,s[0].split())
a = []
b = []
l = np.array([])
ans = 0
count = 0

for i in range(1,n+1):
	a_dash,b_dash = map(int,s[i].split())
	a.append(a_dash)
	b.append(b_dash)

c = zip(a,b)
c = sorted(c)
a,b = zip(*c)
#a = list(a)
#b = list(b)
a_length = len(a)

for i in reversed(range(m)):
	for j in range(count,a_length):
		if a[j] + i == m:
			l = np.append(l,b[j])
			count += 1
		else:
			break
	print(l)
	if l.shape[0] != 0:
		maximum = np.max(l)
		maximum_index = np.argmax(l)
		ans += maximum
		l = np.delete(l,maximum_index)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
b = []
l = []
ans = 0

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

for i in reversed(range(m)):
	for j in range(len(a)):
		if a[j] + i <= m:
			l.append(b[j])
	if len(l) != 0:
		ans += max(l)
		index = []
		for num in l:
			index = b.index(num)
			a.pop(index)
			b.pop(index)
	l.clear()

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
ABs = []
for i in range(N):
    ABs.append(tuple(map(int,input().split())))

def selector(elem):
    return elem[1]

ABs.sort(key=selector,reverse=True)


value = 0
day = 0
current_value = ABs[0][1]
days = []


for i,(a,b) in enumerate(ABs):
    if current_value != b:
        days.sort(reverse=True)
        for d in days:
            if day + d <= M:
                day += 1
                value += current_value
        current_value = b
        days = [a]
    else:
        days.append(a)

days.sort(reverse=True)
for d in days:
    if day + d <= M:
        day += 1
        value += current_value

print(value)

Submission status: Wrong Answer

Solution code:
a=set()
n,m=map(int,input().split())
ab=[]
for i in range(n):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort(key=lambda x:(x[0],-x[1]))
k=0
ans=0
for i in range(n):
	if k!=ab[i][0]:
		ans+=ab[i][1]
		k=ab[i][0]
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

def solve():
    N, M = map(int , input().split())
    arbeit_A_B = list(list(map(int , input().split())) for _ in range(N))
    arbeit_A_B = sorted(arbeit_A_B, key=lambda x: (x[0], -x[1]))
    # print(arbeit_A_B)
    day = 1
    result = 0
    index_arbeit = 0
    heap_q = []
    while day <= M:
        while index_arbeit < N:
            A,B = arbeit_A_B[index_arbeit]
            if A <= day:
                heappush(heap_q, (-1)*B)
            else: break
            index_arbeit += 1
            
        result -= heappop(heap_q)
        day += 1
            
    print(result)

Submission status: Wrong Answer

Solution code:
def solve():
    N, M = map(int , input().split())
    arbeit_A_B = list(list(map(int , input().split())) for _ in range(N))
    arbeit_A_B = sorted(arbeit_A_B, key=lambda x: (-x[1], -x[0]))
    # print(arbeit_A_B)
    day = 0
    result = 0
    for A, B in arbeit_A_B:
        if day+A <= M:
            result += B
            day += 1
            
    print(result)
    
solve()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, M = map(int, input().split())
    A_B = sorted([list(map(int, input().split())) for _ in range(N)])
    count = 0
    for day in range(M):
        try:
            A_B = sorted(list(filter(lambda x: x[0] <= M-day, A_B)), key=lambda x1: x1[1])
            try:
                count += A_B.pop()[1]
            except IndexError:
                pass
        except ValueError:
            pass
        
    print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))
x = []
for i in range(N):
    x.append(list(map(int, input().split(' '))))

x = sorted(x, key = lambda x:x[1], reverse = True)

cnt = 0
for i in range(N):
    for v in x:
        if v[0] <= M - i:
            a = x.pop(0)[1]
            cnt += a
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort(key=lambda x: x[0], reverse=True)
AB.sort(key=lambda x: x[1], reverse=True)
day = 0
res = 0
for i in range(N):
    a, b = AB[i]
    if day + a <= M:
        res += b
        day += 1

print(res)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])
AB.sort(key=lambda x: x[0], reverse=True)
AB.sort(key=lambda x: x[1], reverse=True)

res = 0
day = 0
for i in range(N):
    a, b = AB[i]
    if day + a <= M:
        res += b
        day += 1
print(res)

Submission status: Wrong Answer

Solution code:
from queue import PriorityQueue


def main():
    N, M = map(int, input().split(' '))
    jobs = [[] for _ in range(M + 1)]
    for i in [input() for i in range(N)]:
        A, B = map(int, i.split(' '))
        if A > M:
            continue
        jobs[A].append(B)

    pq = PriorityQueue()
    reward = 0

    for sameJobs in jobs:
        for reward in sameJobs:
            pq.put(-reward)
        if not pq.empty():
            reward += -(pq.get())

    print(reward)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

from queue import PriorityQueue


def main():
    N, M = map(int, input().split(' '))
    jobs = [[] for _ in range(M + 1)]
    for i in [input() for i in range(N)]:
        A, B = map(int, i.split(' '))
        if A > M:
            continue
        jobs[A].append(B)

    pq = PriorityQueue()
    reward = 0

    print(jobs)

    for sameJobs in jobs:
        print(sameJobs)
        for job in sameJobs:
            pq.put(-job)

        if not pq.empty():
            reward += -(pq.get())

    print(reward)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from queue import PriorityQueue


def main():
    N, M = map(int, input().split(' '))
    jobs = [[] for _ in range(M + 1)]
    for i in [input() for i in range(N)]:
        A, B = map(int, i.split(' '))
        if A > M:
            continue
        jobs[A].append(B)

    pq = PriorityQueue()
    reward = 0

    for sameJobs in jobs:
        for reward in sameJobs:
            pq.put(-reward)

        if not pq.empty():
            reward += -(pq.get())

    print(reward)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#Coding:Utf-8

N,M=list(map(int, input().split()))
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:(x[1],x[0]),reverse=True)
day=0
total=0

for l in range(M):
    A=[x for x in A if x[0]<=M-day]
    if len(A)==0:
        break
    total+=A[0][1]
    del A[0]
    day+=1

print(total)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

N, M = map(int, input().split())
job = []

for i in range(N):
  a, b = map(int, input().split())
  heappush(job, (a,-b))
ans = 0
for i in range(1,M+1):
  a, b = heappop(job)
#  print(a,b,i)
  b = -b
  if a<=i:
    ans += b
  else:
    heappush(job, (a,-b))
  if job==[]:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def get_money(days_and_money, day, M):
    while days_and_money:
        dam = days_and_money.pop(0)
        if dam[0] + day > M:
            continue
        else:
            return dam[1]
    return 0

N, M = [int(x) for x in  input().split()]
days_and_money = []
for _ in range(N):
    days_and_money.append([int(x) for x in  input().split()])

days_and_money.sort(key=itemgetter(1, 0), reverse=True)

money = 0
for day in range(M):
    money += get_money(days_and_money, day, M)

print(money)

Submission status: Wrong Answer

Solution code:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>=M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Submission status: Wrong Answer

Solution code:
max_num = 1000000
min_num = -1000000
k,x = map(int, input().split())
if x + k > 1000000:
    min_num = x - k + 1
elif x - k < -1000000:
    max_num = x + k - 1
else:
    min_num = x - k + 1
    max_num = x + k - 1

for i in range( min_num, max_num + 1 ):
    print(i)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
A = list(list(map(int, input().split())) for _ in range(n))
d = 0
for i in range(m):
    B = [0]
    for a, b in A:
        if a < m-i:
            B.append(b)
    d += max(B)
print(d)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import heapq
N,M=map(int,input().split())
x=defaultdict(list)
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(b)
y=[]
an=0
for i in range(M+1):
    y+=x[i]
    heapq.heapify(y)
    try:
        an+=y.pop()
    except:
        pass
print(an)

Submission status: Wrong Answer

Solution code:
from functools import reduce

      
N, total_days = map(int, input().split())
jobs = []
job_listing = [[] for _ in range(total_days+1)]
for _ in range(N):
  days, earnings = map(int, input().split())
  if days > total_days: continue
  else: job_listing[days].append(earnings)
    
job_listing = list(map(lambda x: sorted(x), job_listing))
schedules = [0 for _ in range(total_days + 1)]

for i in range(1, total_days + 1):
  if job_listing[i]:
    schedules[i] = job_listing[i].pop()
  else:
    for j in range(i, 0, -1):
      if job_listing[j]:
        schedules[i] = job_listing[j].pop()
      else: continue
        
print(reduce((lambda x,y: x+y), schedules))

Submission status: Wrong Answer

Solution code:
import heapq

n,m = map(int,input().split())

a = [[] for i in range(100000)]
d = []
heapq.heapify(d)

for _ in range(n):
    b,c = map(int,input().split())
    a[b-1].append(-1 * c)

#print(a)

ans = 0
for i in range(m):
    for j in range(len(a[i])):
        heapq.heappush(d,a[i][j])
    if d == []:
        break
    ans -= heapq.heappop(d)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ABList = [[] for _ in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a-1>m-1:
        continue
    ABList[a-1].append(b)

ans = 0
while m > 0:
    m = m-1
    for i in range(m,-1,-1):
        if len(ABList[i])>0:
            B = ABList[i].pop(ABList[i].index(max(ABList[i])))
            ans += B       
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ABList = [[] for _ in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a-1>m-1:
        continue
    ABList[a-1].append(b)

ans = 0
while m > 0:
    m = m-1
    for i in range(m,-1,-1):
        if len(ABList[i])>0:
            B = max(ABList[i])
            ans += B       
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
c=list(map(int,input().split()))
n,m=c[0],c[1]
c=np.array([list(map(int,input().split())) for i in range(n)])
boo=np.zeros(m)
one=np.ones(m)
c=c[c[:,1].argsort(), :]
index=n-1
value=0
maxK=m
while(index>=0):
	k=c[index,0]
	if k<= maxK:
		if boo[k-1]==m-k:
			boo[:k]=boo[:k]+one[:k]
			value=value+c[index,1]
			maxK=k-1
		elif boo[k-1]<m-k:
			boo[:k]=boo[:k]+one[:k]
			value=value+c[index,1]
	index=index-1
print(value)

Submission status: Wrong Answer

Solution code:
import numpy as np
c=list(map(int,input().split()))
n,m=c[0],c[1]
c=np.array([list(map(int,input().split())) for i in range(n)])
boo=np.zeros(m)
one=np.ones(m)
c=c[c[:,1].argsort(), :]
index=n-1
value=0
maxK=m
j=m
while(j>0):
	if index<0 :break
	while(index>=0):
		k=c[index,0]
		if k<= maxK:
			if boo[k-1]==m-k:
				boo[:k]=boo[:k]+one[:k]
				value=value+c[index,1]
				j=j-1
				maxK=k-1
			elif boo[k-1]<m-k:
				boo[:k]=boo[:k]+one[:k]
				value=value+c[index,1]
				j=j-1
		index=index-1
print(value)

Submission status: Wrong Answer

Solution code:
import numpy as np
c=list(map(int,input().split()))
n,m=c[0],c[1]
c=np.array([list(map(int,input().split())) for i in range(n)])
boo=np.zeros(m)
one=np.ones(m)
c=c[c[:,1].argsort(), :]
index=n-1
value=0
maxM=m-1
j=m
while(j>0):
	if index<0 :break
	while(index>=0):
		k=c[index,0]
		if k<= maxM+1:
			if boo[k-1]<m-k+1:
				boo[:k]=boo[:k]+one[:k]
				value=value+c[index,1]
				j=j-1
			else:
				maxM=k-2
		index=index-1
print(value)

Submission status: Wrong Answer

Solution code:
#input
N, M = map(int, input().split())
A = [0] * N
B = [0] * N

for i in range(N):
    A[i], B[i] = map(int, input().split())

#output
import heapq

#点数配列の用意
point = 0
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for j in range(0, M):
    for i in range(N):
        if A[i] <= j+1:
            heapq.heappush(hq, -B[i])
        if len(hq):
            point += -heapq.heappop(hq)

print(point)

Submission status: Wrong Answer

Solution code:
import heapq
import sys

h = []
n,m = list(map(int,input().split(" ")))



nums = []
for i in range(n):
    a,b = list(map(int,input().split(" ")))
    nums.append((a,b))
nums.sort(key=lambda x:x[0])

d = 1
ans = 0
st = 0
for d in range(1,m+1):
    for i in range(st,n):
        if nums[i][0] > d:
            st = i
            flag = True
            break
        else:
            heapq.heappush(h,-nums[i][1])

    if h:
        ans -= heapq.heappop(h)


print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import sys

h = []
n,m = list(map(int,input().split(" ")))



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

    heapq.heappush(h,(-b,-a))
d = 0
ans = 0
while d != m and h:

    while h :
        b,a = heapq.heappop(h)
        a = -a
        b = -b
        if m - d >= a: # m-d → 残り日数
            ans += b
            break

    d += 1

print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
print(jobs)
score = 0
for i in range(b):
  max_now = 0
  deli = []
  for j in range(len(jobs)):
    job = jobs[j]
    if job[0] <= i + 1:
      if max_now < job[1]:
        max_now = job[1]
        deli = job
  score += max_now 
  if deli != []:
    jobs.remove(deli)
print(score)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
input = sys.stdin.readline

class maxq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
    def top(self):
        return self.hq[0] * self.sign
    def extend(self, arr):
        return self.hq.extend([a * self.sign for a in arr])
        

n, m = map(int, input().split())
q = []
to = {}
day = [0 for _ in range(m)]
count = 0
for i in range(n):
    a, b = map(int, input().split())
    to[a-1] = to.get(a-1, [])
    to[a-1].append(b)
for i in range(m):
    q.extend(to.get(i, []))
    if len(q) == 0:
        continue
    q = maxq(q, True)
    count += q.pop()
    q = q.hq
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
c=list(map(int,input().split()))
n,m=c[0],c[1]
c=np.array([list(map(int,input().split())) for i in range(n)])
boo=[0]*m
c=c[c[:,1].argsort(), :]
index=n-1
value=0
while(m>0):
  if index<0 :break
  while(index>=0):
    if c[index,0]<= m:
      value=value+c[index,1]
      m=m-1
      index=index-1
      break
    index=index-1
print(value)

Submission status: Wrong Answer

Solution code:
#input
N, M = map(int, input().split())
A = [0] * N
B = [0] * N

for i in range(N):
    A[i], B[i] = map(int, input().split())

#output
import heapq

#点数配列の用意
point = [0] * M
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for j in range(0, M):
    for i in range(N):
        if A[i] == j + 1:
            heapq.heappush(hq, -B[i])
    if len(hq) > 0:
        point[j] = -heapq.heappop(hq)

sum(point)

Submission status: Wrong Answer

Solution code:
#input
N, M = map(int, input().split())
A = [0] * N
B = [0] * N

for i in range(N):
    A[i], B[i] = map(int, input().split())

#output
import heapq

#点数配列の用意
point = [0] * M
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for j in range(0, M):
    for i in range(N):
        if A[i] == j+1:
            heapq.heappush(hq, -B[i])
    if len(hq) > 0:
        point[j] = -heapq.heappop(hq)
point
sum(point)

Submission status: Wrong Answer

Solution code:
# import numpy as np

N,M=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N)]
A.sort()

# A = np.array(A)

cnt = 0

for day in range(1,M+1):
    B = [x[1] for x in A if x[0]<=day]
    if B:
        ind = B.index(max(B))
        cnt += B[ind]
        A[ind][1] = -1
print(cnt)

Submission status: Wrong Answer

Solution code:
#Binary Indexed Tree (1-index！！！！！！！！)
class BinaryIndexedTree():
    def __init__(self, size):
        self.__node = [0] * (size+1)
        self.size = size

    #node[index]にvalueを足して、BITを更新 O(logN)
    def add(self, index, value):
        while index <= self.size:
            self.__node[index] += value
            index += index&-index    
    
    #indexまでの和を返す O(logN)
    def sum(self, index):
        ret = 0 #零元・単位元
        while index > 0:
            ret += self.__node[index]
            index -= index&-index    
        return ret

    def update_max(self, index, value):
        while index <= self.size:
            self.__node[index] = max(self.__node[index], value)
            index += index & -index


    #indexまでの最大値を返す
    def query_max(self, index):
        ret = 0
        while index > 0:
            ret = max(ret, self.__node[index])
            index -= index & -index
        return ret
        
        

    #0-indexでの添字を受け取って、1-indexでの添字での値を返す
    def get_node(self, index):
        return self.__node[index]

    def show(self):
        #print(self.__node)
        for day in range(1,self.size+1):
            print("day,",day,self.sum(day))

#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M= MI()
    works = LLIN(N)
    works.sort(key = itemgetter(1),reverse = True)
    BIT = BinaryIndexedTree(M)
    used = set()
    #print(works)

    for day in range(1,M+1):
        #print(day)
        BIT.add(day,1)
    ans = 0
    for day, money in works:
        #BIT.show()
        date = M-day+1
        if BIT.sum(date)>0:
            #print(date)
            if date in used:
                if date-1>0:
                    BIT.add(date-1, -1)
                else:
                    continue
            else:
                used.add(date)
                BIT.add(date, -1)
            ans += money
    print(ans)
    
    
if __name__ == '__main__':
    main()