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:
N,M=map(int,input().split())

balist=[]
for i in range(N):
  A,B=map(int,input().split())
  balist.append((B,A))
  
balist.sort(reverse=True)
#print(balist)

answer=0
day=0
for (b,a) in balist:
  if day+a<=M:
    print(b,day+a)
    answer+=b
    day+=1
    
  if day>=M:
    break
    
print(answer)

Submission status: Wrong Answer

Solution code:
n, time = map(int, input().split())
dp = [0 for i in range(time+1)]
for i in range(n):
    v, w = map(int, input().split())
    for j in range(time, w-1, -1):
        dp[j] = max(dp[j], dp[j-w]+v)
print(dp[time])

Submission status: Wrong Answer

Solution code:
n, time = map(int, input().split())
dp = [0 for i in range(time+1)]
for i in range(n):
    v, w = map(int, input().split())
    for j in range(time, w, -1):
        dp[j] = max(dp[j], dp[j-w]+v)
print(dp[time])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n): 
    a,b=map(int,input().split())
    l.append([a,b])
    #b afer a days 
#l=[]
l.sort(key=lambda x:[-x[1],-x[0]])
#print(l)
sm=0 
day=0 
#print(l)
for i in range(n): 
    #print(day,l[i][0],l[i][1])
    if day+l[i][0]<=m: 
        sm+=l[i][1]
        #print(i,sm)
        day+=1 
    else: 
        pass 
print(sm)

Submission status: Wrong Answer

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

for _ in range(N):
    a, b = map(int, input().split())
    jobs.append((a -1,b))

jobs = sorted(jobs, key=lambda x: x[1])
# 報酬でソート

day = 1
ans = 0

while day <= M and jobs:
    todays_job = jobs.pop()

    if todays_job[0] + day <= M :
    # 給料日までの期間が残り期間よりも短いなら
        ans += todays_job[1]
    else:
        pass

    day += 1

print(ans)

Submission status: Wrong Answer

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

for _ in range(N):
    a, b = map(int, input().split())
    jobs.append((a -1,b))

jobs = sorted(jobs, key=lambda x: x[1])
# 報酬でソート

day = 1
ans = 0

while jobs:
    todays_job = jobs.pop()

    if todays_job[0] + day <= M :
    # 給料日までの期間が残り期間よりも短いなら
        ans += todays_job[1]
    else:
        pass

    day += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect, heapq

N, M = map(int, input().split())
income = [[] for _ in range(M+1)] # income[i]はi日後に報酬が得られる全ての仕事についての報酬のリスト
for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        bisect.insort_left(income[a], -b)

# 後ろから考える。残りi日のときに終了までに報酬が得られる仕事のうち報酬最大のものを選ぶ
ans = 0
for rest_days in range(1, M+1):
    if income[rest_days]:
        if ans == 0:
            heapq.heapify(income[rest_days])
        ans += heapq.heappop(income[rest_days])
        if rest_days < M:
            income[rest_days+1] = list(heapq.merge(income[rest_days+1], income[rest_days]))

print(-ans)

Submission status: Wrong Answer

Solution code:
from sys import exit
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    income = 0
    daysUsed = 0
    if len(jobs) == 0:
        print(0)
        exit()

    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft >= 0:
            income += job[1]
            daysUsed += 1
        elif daysLeft == -1 and len(jobs) > 1:
            income += job[1]
            break
    print(income)

Submission status: Wrong Answer

Solution code:
from sys import exit
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    income = 0
    daysUsed = 0
    if len(jobs) == 0:
        print(0)
        exit()

    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft >= 0:
            income += job[1]
            daysUsed += 1
        elif daysLeft == -1:
            income += job[1]
            break
    print(income)

Submission status: Wrong Answer

Solution code:
from sys import exit
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    income = 0
    daysUsed = -1
    if len(jobs) == 0:
        print(0)
        exit()

    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft > 0:
            income += job[1]
            daysUsed += 1
        else:
            income += job[1]
            break
    print(income)

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    income = 0
    daysUsed = -1
    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft > 0:
            income += job[1]
            daysUsed += 1
        else:
            income += job[1]
            break
    print(income)

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    print("+++++++")
    print(jobs)
    print("+++++++")
    income = 0
    daysUsed = -1
    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft > 0:
            print(job)
            print((m - daysUsed) - job[0])
            income += job[1]
            daysUsed += 1
        else:
            income += job[1]
            break
    print(income)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, M = map(int, stdin.readline().split())

ba = []
for i in range(N):
    temp_a, temp_b = map(int, stdin.readline().split())
    ba.append([temp_b, temp_a])

ba.sort()

day_list = [i for i in range(1, M+1)]
sum_price = 0
for i in reversed(ba):
    price = i[0]
    day = i[1]
    for j, k in enumerate(day_list):
        if k >= day:
            day_list.pop(j)
            sum_price += price

print(sum_price)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
r = [list(map(int, input().split())) for i in range(n)]
r.sort(reverse=True)
r.sort(key=lambda x: x[1], reverse=True)
rev = 0
#day j
for j in range(m):
    if len(r) == 0:
        break
    for i in r:
        if i[0] <= m-j:
            rev += i[1]
            r.remove(i)
            break
        else:
            r.remove(i)
print(rev)

Submission status: Wrong Answer

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


def main():
    N, M = [int(x) for x in input().strip().split()]
    w_list = [[int(x) for x in input().strip().split()] for _ in range(N)]
    w_list = sorted(w_list, key=lambda x: (x[0], -x[1]))
    a_list = [x[0] for x in w_list]
    b_list = [x[1] for x in w_list]
    c_list = [[] for _ in range(M+1)]
    available_work = []
    for idx in range(len(a_list)):
        if a_list[idx] <= M:
            if len(c_list[a_list[idx]]) < M - a_list[idx] + 1:
                c_list[a_list[idx]].append(b_list[idx])
                available_work.append(b_list[idx])
    available_work = sorted(available_work, reverse=True)
    ans = sum(available_work[:M])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def main():
    N, M = [int(x) for x in input().strip().split()]
    w_list = [[int(x) for x in input().strip().split()] for _ in range(N)]
    w_list = sorted(w_list, key=lambda x: (x[0], x[1]))
    a_list = [x[0] for x in w_list]
    b_list = [x[1] for x in w_list]
    c_list = [[] for _ in range(M+1)]
    for idx in range(len(a_list)):
        if a_list[idx] < M:
            c_list[a_list[idx]].append(b_list[idx])

    ans = 0
    for left_day in range(M):
        max_value = 0
        max_day = 0
        for d in reversed(range(left_day+2)):
            if len(c_list[d]) > 0:
                if c_list[d][-1] > max_value:
                    max_day = d
                    max_value = c_list[d][-1]
            #print(left_day+1,d,max_day,max_value)
        ans += max_value
        if len(c_list[max_day]) > 0:
            c_list[max_day].pop()
        
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lis = [[] for _ in range(M)]
sum = 0
for i in range(N):
    a,b = map(int,input().split())
    if a < M:
        lis[a-1].append(-b)
import heapq
heap = []
for i in range(M):
    for e in lis[i]:
        heapq.heappush(heap,e)
    if len (heap) > 0:
        tmp = heapq.heappop(heap)
        sum += -tmp


    
print(sum)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lis = [[] for _ in range(M)]
sum = 0
for i in range(N):
    a,b = map(int,input().split())
    if a-1 < M:
        lis[a-1].append(-b)
print(lis)
import heapq
heap = []
for i in range(M):
    for e in lis[i]:
        heapq.heappush(heap,e)
    if len (heap) > 0:
        tmp = heapq.heappop(heap)
        sum += -tmp


    
print(sum)

Submission status: Wrong Answer

Solution code:
N,M=(int(a) for a in input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    A[i],B[i]=(int(b) for b in input().split())

max=0
count=0
for x in reversed(range(0,M+1)):
    indexes = [i for i, m in enumerate(A) if m==x]
    if len(indexes)!=0:
        for y in range(len(indexes)):
            if max<B[indexes[y]]: max=B[indexes[y]]
        count=count+max
        max=0
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
r = [list(map(int, input().split())) for i in range(n)]
r.sort(key=lambda x: x[1], reverse=True)
rev = 0
print(r)
#day j
for j in range(m):
    if len(r) == 0:
        break
    for i in r:
        if i[0] <= m-j:
            rev += i[1]
            r.remove(i)
            break
        else:
            r.remove(i)
print(rev)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
r = [list(map(int, input().split())) for i in range(n)]
r.sort(key=lambda x: x[1], reverse=True)
rev = 0
print(r)
#day j
for j in range(m):
    for i in r:
        if i[0] <= m-j:
            rev += i[1]
            r.remove(i)
            break
        else:
            r.remove(i)
print(rev)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lis = []
sum = 0
last_day = 0
for i in range(N):
    a,b = map(int,input().split())
    lis.append((b,a))
lis.sort(reverse=True)
for i in range(N):
    if lis[i][1] <= M - last_day:
        sum += lis[i][0]
    last_day += 1
print(sum)

Submission status: Wrong Answer

Solution code:
import heapq
def main():
  N, M = list(map(int, input().split()))
  jobs = [[] for _ in range(M)]
  for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
      jobs[d-1].append(-r)

  m = 0
  heap = []
  for i in range(M):
    for a in jobs[i]:
      heapq.heappush(heap, a)
    if len(heap) > 0:
      b = heapq.heappop(heap)
      m += -b
  return m
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
xs = []
for _ in range(n):
    a, b = map(int,input().split())
    xs.append((a,b))

from heapq import *
sxs = sorted(xs)
ri = sxs[0][0]
s = []
r = 0
for a, b in sxs:
    if ri > m:
        break
    if a == ri:
        heappush(s, -b)
        continue
    while True:
        if len(s):
            r -= heappop(s)
        ri+=1
        if a == ri:
            heappush(s, -b)
            break
while True:
    if ri > m:
        break
    if len(s):
    #    print(ri, s,r)
        r -= heappop(s)
    ri += 1
print(r)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
xs = []
for _ in range(n):
    a, b = map(int,input().split())
    xs.append((a,b))

from heapq import *
sxs = sorted(xs)
ri = sxs[0][0]
s = []
r = 0
for a, b in sxs:
    heappush(s, -b)
    if a == ri:
        continue
    while True:
        if len(s) > 1:
            r -= heappop(s)
#print(ri, s, r)
        ri+=1
        if a == ri:
            break
if len(s):
#    print(ri, s,r)
    r -= heappop(s)
print(r)

Submission status: Wrong Answer

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

C = [[0,0] * x for x in range(N)] 
for i in range(N):
  C[i] = list(map(int, input().split()))
C.sort(key=lambda x: (x[1], x[0]), reverse=True)

cnt = 0
while len(C) > 0:
  m = C.pop(0)
  if m[0]<= M:
    M = M - 1
    cnt = cnt + m[1]

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
s=[]
for i in range(N):
  s.append(list(map(int,input().split())))
a=sorted(s,key=lambda x:x[1],reverse=True)
b=sorted(a,key=lambda x:x[0])
print(b)
date=M-1
d=1
c=0
while date>=0:
  if b[0][0]==d:
    c=c+b[0][1]
  
  
  
  date=date-1
  d=d+1
print(c)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
days = [0 for i in [0]*M]
works = []
for n in [0]*N:
    works.append(list(map(int, input().split())))
works = sorted(works, key=lambda x:x[1])[::-1]
for day in range(M):
    for work in works:
        if day+work[0] <= M:
            days[day] = work[1]
            works.remove(work)
            break
print(sum(days))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
NM = []
count_N = 0
for i in range(N):
  tmp = []
  A_,B_ = map(int,input().split())
  if A_ <= M:
    tmp.append(B_)
    tmp.append(A_)
    NM.append(tmp)
    count_N += 1

NM.sort(reverse=True)
print(NM)

count = 0
for i in range(M):
  for j in range(count_N):
    if NM[j][1] <= M-i:
      count += NM[j][0]
      del NM[j]
      count_N -= 1
      break;

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
    print(ans)
    return

#D
def D():
    n, m = LI()
    ab = LIR(n)
    ab.sort(key=lambda x: (x[1], x[0]), reverse=True)
    ans = 0
    for i in range(n):
        if m >= ab[i][0]:
            ans += ab[i][1]
            m -= 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
n,m = (int(i) for i in input().split())
x = []
for _ in range(n):
    a,b = (int(i) for i in input().split())
    x.append((-b,a))
d,x,ans = [0]*(m+1),sorted(x),0
def add(i):
	while i<=m:
		d[i]+=1
		i += i & -i
def get(i):
	s = 0
	while i:
		s+=d[i]
		i -= i & -i
	return s
for i in range(n):
    if x[i][1]<=m and get(x[i][1]-1)>x[i][1]+i-m-1:
        add(x[i][1])
        ans-=x[i][0]
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n,m = map(int,input().split())
Jobs = [list(map(int,input().split()))for i in range(n)]

Days = [[] for i in range(m)]
for i in range(n):
    if Jobs[i][0] <= m-1:
        Days[Jobs[i][0]-1] += [[-Jobs[i][1],Jobs[i][0]]]

Heap = []
heapq.heapify(Heap)
ans = 0
for i in range(m):
    for job in Days[i]:
        heapq.heappush(Heap,job)
    if Heap:
        ans -= heapq.heappop(Heap)[0]
        
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,raw_input().split())
A_B = []
A_B_N = []
for i in range(0,N):
  A_B = list(map(int,raw_input().split()))
  A_B_N.append(A_B)
A_B_N = (sorted(A_B_N, key=lambda x:(x[1],x[0]),reverse = True))
pastDate = 0
ans = 0
while True:
  print A_B_N
  if A_B_N[0][0] + pastDate <= M:
    ans = ans + A_B_N[0][1]
    pastDate += 1
  del(A_B_N[0])
  if len(A_B_N) == 0:
    break
print ans

Submission status: Wrong Answer

Solution code:
#AtCoder

import sys
import math
import itertools
input = sys.stdin.readline

N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

reward = 0
for m in range(M+1):
	BMAX = -1
	index = -1
	for i in range(len(A)):
		if A[i] <= m and BMAX < B[i]:
			BMAX = B[i]
			index = i
	if BMAX != -1:
		reward += BMAX
		print(BMAX, index)
		A.pop(index)
		B.pop(index)
	else:
		print("No")

print(reward)



"""

"""

Submission status: Wrong Answer

Solution code:
N,M = map(int,raw_input().split())
A_B = []
A_B_N = []
for i in range(0,N):
  A_B = list(map(int,raw_input().split()))
  A_B_N.append(A_B)
A_B_N = (sorted(A_B_N, key=lambda x:(x[1],x[0]),reverse = True))
pastDate = 0
ans = 0
for i in range(0,M):
  if len(A_B_N) == 0:
    if len(A_B_N) == 0:
      break
  while True:
    if A_B_N[0][0] + pastDate <= M:
      ans = ans + A_B_N[0][1]
      del(A_B_N[0])
      pastDate += 1
      break
    del(A_B_N[0])
    if len(A_B_N) == 0:
      break
print ans

Submission status: Wrong Answer

Solution code:
N,M = map(int,raw_input().split())
A_B = []
A_B_N = []
for i in range(0,N):
  A_B = list(map(int,raw_input().split()))
  A_B_N.append(A_B)
A_B_N = (sorted(A_B_N, key=lambda x:(x[1], x[0]),reverse = True))
pastDate = 0
ans = 0
for i in range(0,M):
  for j in A_B_N:
    if A_B_N[0][0] + pastDate <= M:
      ans = ans + A_B_N[0][1]
      del(A_B_N[0])
      pastDate += 1
      break
    del(A_B_N[0])
print ans

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
input=sys.stdin.readline
n,m=map(int,input().split())
ab=[[0,0]]*n
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab,key=itemgetter(1,0),reverse=True)
count=0
take=0
for i in range(m+1):
    for j in range(n-take):
        outline=m-(i+ab[j][0])
        if outline>=0:
            take+=1
            count+=ab[j][1]
            ab.pop(j)
            break
print(count)

Submission status: Wrong Answer

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

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

ab.sort()
ze=[j[0] for j in ab]
index=[N+1]
for i in range(M):
  if M-i in ze:
    index.append(ze.index(M-i))
  else:
    index.append(index[i])
index.reverse()
    
sal=0
poss=[]
for i in range(1,M+1):
  for j in ab[index[i-1]:index[i]]:
    heapq.heappush(poss,-j[1])
  if len(poss)>0:
    sal+=-heapq.heappop(poss)
    
print(sal)

Submission status: Wrong Answer

Solution code:
import heapq

N,M = (int(i) for i in input().split()) 
ab = [[-int(i) for i in input().split()][::-1] for i in range(N)] 

ans=0
dead=0
heapq.heapify(ab)

while True:
	if ab==[]:
		break
	_max = heapq.heappop(ab)
	if _max[1]*(-1) <= M-dead:
		ans += _max[0]*(-1)
		dead+=1		

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)

H = []
heapq.heapify(H)
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        H += d_AB[i]
        money += heapq.heappop(H)
        
    else:
        money += heapq.heappushpop(H,0)

print(-money)

Submission status: Wrong Answer

Solution code:
import heapq
n, m = [ int(v) for v in input().split() ]
work_list = [ [] for i in range(m)]
collect_list = [] 
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    if m-a >= 0:
        work_list[m-a].append(-b)
 
 
for i in range(m):
    for j in range(min(i+1,len(work_list[i]))):
        heapq.heappush(collect_list,heapq.heappop(work_list[i]))
 
heapq.heapify(collect_list)
ans = 0
for i in range(min(m,len(collect_list))):
    ans -= heapq.heappop(collect_list)
print(ans)

Submission status: Wrong Answer

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

AB.sort(reverse=True, key=lambda x:x[0])
AB.sort(reverse=True, key=lambda x:x[1])

day = 0
salary = 0

for a,b in AB:
    if day+a<=M:
        day += 1
        salary += b

print(salary)

Submission status: Wrong Answer

Solution code:
#Summer Vacation -D-
n,m=map(int,input().split())
ba=[]
for i in range(n):
    a,b=map(int,input().split())
    ba.append([b,a])
ba.sort()
k=1
l=0
sum=0
while ba:
    if ba[n-k][1]<=m-l:
        sum+=ba[n-k][0]
        k+=1
        l+=1
        ba.pop()
    else:
        k+=1
        ba.pop()
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import heapq
n,m=map(int,input().split())
dic=defaultdict(list)
for i in range(n):
    a,b=map(int,input().split())
    dic[a]+=[-b]
    
li=[]
ans=0
print(dic)
for i in range(1,m+1):
    if dic[i]:
        for j in dic[i]:
            heapq.heappush(li,j)
    if li:
        ans+=heapq.heappop(li)
print(-ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from bisect import bisect_right
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
work=defaultdict(list)
for A, B in lst:
  work[A].append(B)
for k in list(work.keys()):
  work[k].sort()
ans=0
for day in range(1, M+1):
  days=list(work.keys())
  idx=bisect_right(days, day)
  if idx==0:
    continue
  maxi=0
  maxv=work[days[maxi]][-1]
  for i in range(idx):
    if maxv<work[days[i]][-1]:
      maxv=work[days[i]][-1]
      maxi=i
  ans+=work[days[maxi]].pop()
  if not work[days[maxi]]:
    work.pop(days[maxi])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
     import heapq
     import sys
     input=sys.stdin.readline

     ans=0
     N,M=map(int,input().split())
     Ar=[]
     for _ in range(M):
           Ar.append([])
     for _ in range(N):
          A,B=map(int,input().split())
          if A <= M:
              Ar[A-1].append(-B)
     An=[]
     for i in range(M):
          for j in Ar[i]:
              heapq.heappush(An,j)
              ans+=-heapq.heappop(An)
     print(ans)

if __name__ =='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from bisect import bisect_right
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
work=defaultdict(list)
for a, b in lst:
  work[b].append(a)
for k in work.keys():
  work[k].sort()
ans=0
while M>0 and len(work)>0:
  max_profit=list(work.keys())[-1]
  i=bisect_right(work[max_profit], M)
  if i==0:
    work.pop(max_profit)
    continue
  ans+=max_profit
  work[max_profit].pop(i-1)
  M-=1
  if not work[max_profit]:
    work.pop(max_profit)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

AB=np.arange(12).reshape(4, 3)
print(AB.tolist())

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

work_list = [list(map(int,input().split())) for i in range(N)]
work_list.sort()

sum = 0
for j in range(M+1):
    hoshu = 0
    t = N+1
    k = 0

    while (k <= N-1 and work_list[k][0] <= j):
        hoshu = max(hoshu, work_list[k][1])
        t = k
        k += 1
    sum += hoshu

    if t != N+1:
        del work_list[t]
        N -= 1

print(sum)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
task = []
for i in range(N):
	A, B = getlist()
	task.append([B, A])

task = sorted(task)
ans = 0

for i in range(N):
	if task[-1 - i][1] <= M:
		ans += task[-1 - i][0]
		M -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
task = []
for i in range(N):
	A, B = getlist()
	task.append([B, A])

task = sorted(task)
print(task)
ans = 0

for i in range(N):
	if task[-1 - i][1] <= M:
		ans += task[-1 - i][0]
		M -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
task = []
for i in range(N):
	A, B = getlist()
	task.append([B, A])

task = sorted(task)

ans = 0
v = 0
while v < N:
	if task[-1 - v][1] <= M:
		ans += task[-1 - v][0]
		M -= 1
	v += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
task = []
for i in range(N):
	A, B = getlist()
	task.append([B, A])

task = sorted(task)

ans = 0
v = 0
while v < N:
	if task[-1 - v][1] <= M:
		ans += task[-1 - v][0]
		N -= 1
	v += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: x[0], reverse=True) if part_time[0] <= M]
    money = 0
    day = 0
    earns = []

    for [income_day, earn] in part_times:
        remain_day = M - day
        if remain_day >= income_day:
            money += earn
        else:
            min_earn = min(earns)
            if earn > min_earn:
                money += earn
                money -= min_earn
                earns.remove(min_earn)
        earns.append(earn)
        day += 1
    print(money)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: (x[0], x[1]), reverse=True) if part_time[0] <= M]
    money = 0
    day = 0
    earns = []

    for [income_day, earn] in part_times:
        remain_day = M - day
        if remain_day >= income_day:
            money += earn
        else:
            min_earn = min(earns)
            if earn > min_earn:
                money += earn
                money -= min_earn
                earns.remove(min_earn)
        earns.append(earn)
        day += 1
    print(money)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N,M = [int(n) for n in input().split()]
    jobs = [[] for _ in range(10002)]
    v = 0
    for i in range(N):
        a,b = [int(n) for n in input().split()]
        if a <= M:
            jobs[b].append((a,b))
            v = max(v,b)
    jobs = jobs[:v+1]
    # 時間でソート(昇順)
    for i in range(v+1):
        jobs[i] = sorted(jobs[i])
    ans = 0
    jobs_k = len(jobs)-1

    for i in range(jobs_k,-1,-1):
        while(len(jobs[i]) != 0):
            if(jobs[i][-1][0] <= M):
                ans+=i
                M-=1
                jobs[i].pop()
            else:
                jobs[i].pop()
        if M == 0:
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N,M = [int(n) for n in input().split()]
    jobs = [[] for _ in range(10002)]
    v = 0
    for i in range(N):
        a,b = [int(n) for n in input().split()]
        if a <= M:
            jobs[b].append((a,b))
            v = max(v,b)
    jobs = jobs[:v+1]
    # 時間でソート(昇順)
    for i in range(v+1):
        jobs[i] = sorted(jobs[i])
    ans = 0
    jobs_k = len(jobs)-1

    for i in range(jobs_k,-1,-1):
        while(len(jobs[i]) != 0 and jobs[i][-1][0] <= M):
            ans+=jobs[i][-1][1]
            M-=1
            jobs[i].pop()
        if M == 0:
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N,M = [int(n) for n in input().split()]
    jobs = []
    for i in range(N):
        a,b = [int(n) for n in input().split()]
        if a <= M:
            jobs.append((a,b))
    # 時間のあとに価値でソート
    jobs = sorted(jobs, key=lambda x: x[0])
    jobs = sorted(jobs, key=lambda x: x[1])
    # debug(jobs, "(期限、価値)")
    ans = 0
    job_n = len(jobs)
    while(M>0 and job_n):
        for _ in range(job_n):
            # debug(jobs,'jobs')
            # 報酬が間に合わない
            if jobs[-1][0] > M:
                jobs.pop()
            else:
                ans += jobs[-1][1]
                debug(jobs[-1][1],"day" + str(M))
                jobs.pop()
                M-=1
                break
        job_n = len(jobs)
    print(ans)


if __name__ == "__main__":
    main()