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:
from operator import itemgetter
from collections import deque

n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]
ab.sort(key=itemgetter(1), reverse=True)
ab.sort(key=itemgetter(0))
sorted_ab = deque(ab)

count = 0
for i in range(1, 1+m):
  max_v = 0
  for j in range(len(sorted_ab)):
    e = sorted_ab[j]
    if e[0] > i:
      break
    if j >= 1 and sorted_ab[j][0] == sorted_ab[j-1][0]:
      break
    if max_v < e[1]:
      max_v = e[1]
      idx = j
  if max_v > 0:
    del sorted_ab[idx]

  # print((sorted_ab, max_v))
  count += max_v

print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))

ans = 0
while m > 0:
    ab = list(filter(lambda x: x[0] <= m, ab))
    if len(ab) == 0:
        break
    revenue = max(list(map(lambda x: x[1], ab)))
    delete_ab = sorted(list(filter(lambda x: x[1] == revenue, ab)), reverse=True)[0]
    ab.remove(delete_ab)
    ans += delete_ab[1]
    m -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
def f(a, n, m):
    sum = 0
    cnt = 0
    for i in range(n):
        if (cnt + a[i][0] <= m):
            sum += a[i][1]
            cnt += 1
        if(cnt == m):
            break
    return sum


n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
b = sorted(sorted(a, key=lambda x: x[0], reverse=True), key=lambda x: x[1], reverse=True)
c = sorted(sorted(a, key=lambda x: x[1], reverse=True), key=lambda x: x[0], reverse=True)

ans = max(f(b, n, m), f(c, n, m))
print(ans)

Submission status: Wrong Answer

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

n,m=map(int,input().split())
l=[[0,0,0] for _ in range(n)]
for i in range(n):
        l[i][1],l[i][0]=map(int,input().split())
        l[i][0]+=l[i][1]
l.sort()
l=l[::-1]
income=0
day=0

for j in range(n):
    if day+l[j][1]<=m:
            income+=l[j][0]-l[j][1]
            day+=1
    else:
            day+=1

print(income)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(n):
  p,q=map(int,input().split())
  a.append([q,p])
b=sorted(a,key=lambda x:(-x[0],x[1]))

res=0
for i in range(n):
  if i+a[i][1]<=m:
    res+=a[i][0]
print(res)

Submission status: Wrong Answer

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

print(ans)

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])
l.sort(key=lambda x: x[0], reverse=True)
l.sort(key=lambda x: x[1], reverse=True)
day=0
ans=0
for i in range(n):
    if l[i][0]<=m-day:
        day+=1
        ans+=l[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1],reverse=True)
l=[m-i for i in range(m)]
l.insert(0,0)
x=[]
def hiku(y):
    return y-1
for i in range(n):
    if ab[i][0]<=m and l[ab[i][0]]>0:
        x.append(ab[i])
        l[:m-i]=list(map(hiku,l[:m-i]))
        if ab[i][0]>=(m-i):
            l[ab[i][0]]-=1
    else:
        continue

ans=0
for i in range(min(len(x),m)):
    ans+=x[i][1]
print(ans)

Submission status: Wrong Answer

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

def main():
    N, M = map(int, input().split())
    ab = []
    for i in range(N):
        a, b = map(int, input().split())
        if a <= M:
            ab.append([a, b])
    ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

    # for i in range(N):
    #     print(ab[i])
    
    ans = 0
    check = [False] * len(ab)
    for i in range(M):
        for j in range(len(ab)):
            if not check[j]:
                if ab[j][0] <= M - i:
                    ans += ab[j][1]
                    check[j] = True
                    break
    print(ans)

        

    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m = [ int(v) for v in input().split() ]
salary_list = [ [] for i in range(m) ]
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    a = m - a
    if a >= 0:
        salary_list[a].append(b)

salary_list = [sorted(i,reverse = True) for i in salary_list]


ans_list = []
k = 0
for i in range(m):
    for j in range(min(i+1,len(salary_list[i]))):
        ans_list.append(salary_list[i][j])

ans_list = sorted(ans_list,reverse = True)

print(sum(ans_list[:m]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,M = inputMap()
	ab = []
	cnt = {}
	for i in range(N):
		a,b = inputMap()
		if M >= a:
			ab.append((a,b))

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

	aa_tmp = aa[:M]
	ans = 0
	for i in aa_tmp:
		a,b = i
		ans += b
	print(ans)

'''
	ans = 0
	#print(aa)
	for i in range(M,0,-1):
		#print(i)
		for j, val in enumerate(aa):
			a,b = val
			#print("{} {}".format(a,i))
			if i >= a:
				cnt[a] -= 1
				ans += b
				aa.pop(j)
				#print(aa)
				break
			else:
				aa.pop(j)
				'''

	#print(ans)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

an = []

for _ in range(n):
    a, b = map(int, input().split())
    an.append((a,b))
an.sort( key = lambda v:v[0]*-1)
an.sort( key = lambda v:v[1]*-1)
#print('--')
#print(an)
d = m
ans = 0
while 0 <= d:
    for i, job in enumerate(an):
        if job[0] <= d:
            #print("d is {}".format(d))
            ans += job[1]
            #print("do {} {}".format(job[0], job[1]))
            del an[i]
            #print(an)
            break
    d -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def update(i, x):
    i += 1
    while i < m + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

n, m = map(int, input().split())
bit = [0] * (m + 2)
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:(-x[1],-x[0]))
cnt = 0
ans = 0
for a,b in ab:
    if a <= m:
        a = m - a
        if get_sum(a) < a + 1:
            update(a, 1)
            cnt += 1
            ans += b
    if cnt==m:break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB = [[0,0]]* N
for i in range(N):
    AB[i] = list(map(int,input().split()))

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


reward = 0

for i in range(N):
    if AB[i][0] > M:
        continue
    else:
        reward += AB[i][1]
        M = M - 1

print(reward)

Submission status: Wrong Answer

Solution code:
import sys
import copy

N,M=map(int, sys.stdin.readline().split())
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]

A.sort(key=lambda x:(-x[1],-x[0]) )

ans=0
cnt=0
t=copy.deepcopy(M)
for a,b in A:
	if a<=t:
		ans+=b
		cnt+=1
		t-=1
	if cnt==M:
		print ans
		quit()
else:
	print ans

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ab_list = []
result = 0
for i in range (n):
    ab_list.append(list(map(int, input().split())))
ab_list.sort(key=lambda x: x[0], reverse=True)
ab_list.sort(key=lambda x: x[1], reverse=True)
for i in ab_list:
    if i[0] <= m:
        result += i[1]
        m -= 1
print(result)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
L = [list(map(int,input().split())) for k in range(N)]
L = sorted(L,key = lambda x: (-x[1],-x[0]))

c = M
ans = 0

for k in range(N):
    if L[k][0] <= M:
        ans += L[k][1]
        c -= 1
        if L[k][0] == M:
            M -= 1
    if c == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

dp = [0 for _ in range(100000)]

def main():
    N, M = map(int, input().split())
    A_B = [list(map(int, input().split()))[::-1] for _ in range(N)]
    logging.info("Hello!")

    sorted_A_B = sorted(A_B, reverse=True)
    logging.info(sorted_A_B)


    total = 0
    for i in range(N):
        if i >= M:
            break
        
        if sorted_A_B[i][1] + i <= M:
            total += sorted_A_B[i][0]


    print(total)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
[N,M] = list(map(int,input().split()))
A = []
B = []
for i in range(N):
    [An,Bn] = list(map(int,input().split()))
    A.append(An)
    B.append(Bn)
A = np.array(A)
B = np.array(B)

AB = np.array((A,B))
AB = AB[:,np.argsort(AB[1,:])[::-1]]
output = 0

now = 0
t = M
while now < N:
    st = now
    point = AB[1,now]
    while (now<N)and(AB[1,now]==point):
        if AB[0,now]<=t:
            output += AB[1,now]
            AB[0,now] += 10**5
            t += -1
            now = st
        else:
            now += 1

print(output)

Submission status: Wrong Answer

Solution code:
def dfs(res, depth, path, A, B, time, M):
    res.append(path)
    for i in range(depth, len(A)):
        if time + A[i] <= M:
            dfs(res, depth+i+1, path + [B[i]], A, B, time + 1, M)

N, M = map(int, input().split())
A, B = [], []
res = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
dfs(res, 0, [], A, B, 0, M)
if res:
  print(sum(sorted(res, key=lambda x: sum(x))[-1]))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
job = []
for i in range(n):
    a, b = map(int, input().split())
    job.append([b, a])
list.sort(job, reverse=True)

a = 0
d = 0
for j in job:
    if d + j[1] <= m:
        a = a + j[0]
    d = d + 1
print(a)

Submission status: Wrong Answer

Solution code:
from heapq import*
L=lambda:list(map(int,input().split()))
n,m=L()
c=[]
h=[i+1for i in range(m)]
for i in range(n):
  a,b=L()
  c.append([b,a])
c.sort(key=lambda c:(c[0],c[1]),reverse=1)
a=0
for i in c:
  j=m
  b=True
  while j!=0:
    k=heappop(h)
    if i[1]<=k:
      b=False
      break
    heappush(h,k)
    j-=1
  if b:continue
  m-=1
  a+=i[0]
print(a)

Submission status: Wrong Answer

Solution code:
def f(a, n, m):
    sum = 0
    cnt = 0
    for i in range(n):
        if (cnt + a[i][0] <= m):
            sum += a[i][1]
            cnt += 1
    return sum


n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
b = sorted(sorted(a, key=lambda x: x[0], reverse=True), key=lambda x: x[1], reverse=True)

ans = f(b, n, m)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
jobs = []
for i in range(n):
    jobs.append(tuple(map(int, input().split())))
jobs.sort(key=lambda x:(x[1], x[0]), reverse=True)
count = 0
for i in range(m+1):
    while len(jobs) > 0:
        job = jobs.pop(0)
        if i + job[0] <= m:
            count += job[1]
            break
print(count)

Submission status: Wrong Answer

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

dayprice = [0] * (M + 1)

for a_b in A_B:
    try:
        if dayprice[a_b[0]] == 0:
            dayprice[a_b[0]] = a_b[1]
        else:
            i = 1
            while(True):
                if dayprice[a_b[0] + i] == 0:
                    dayprice[a_b[0] + i] = a_b[1]
                i += 1
    except Exception as e:
        continue

print(sum(dayprice))

Submission status: Wrong Answer

Solution code:
n, m = [int(s) for s in input().split()]
ab = [tuple(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: x[1])[::-1]

print(sum(i for _, i in ab[:m]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
works = [list(map(int, input().split())) for _ in range(N)]
works.sort(key=lambda x:(-x[1], -x[0]))
days = [0] * (M+1)
ans = 0
for work in works:
  if work[0] > M:
    continue
  full = True
  for day in range(work[0], M+1):
    if days[day] == 0:
      days[day] = 1
      ans += work[1]
      full = False
      break
  if full:
    print(ans)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N,M=map(int, sys.stdin.readline().split())
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]

A.sort(key=lambda x:(-x[1],-x[0]) )

ans=0
cnt=0
for a,b in A:
	if a<=M:
		ans+=b
		cnt+=1
		M-=1
	if cnt==M:
		print ans
		quit()
else:
	print ans

Submission status: Wrong Answer

Solution code:
#  --*-coding:utf-8-*--

import heapq


def g(Q, n):
    x = 0

    for i in range(n):
        if len(Q) == 0:
            break

        x += -heapq.heappop(Q)

    return x


def f(AB, M):
    lastA = None
    Q = []
    sumOfB = 0

    for a,b in AB:
        if a > M:
            return sumOfB

        if a != lastA:
            if lastA != None:
                sumOfB += g(Q, a-lastA)

            lastA = a

        heapq.heappush(Q, -b)
            
    sumOfB += g(Q, M-lastA+1)

    return sumOfB


def main():
    N,M = map(int, input().split())
    AB = sorted(list(map(int, input().split())) for i in range(N))

    print(f(AB, M))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

table.sort(key=lambda x:x[1], reverse=True)
count = [0]*M
cnt = 0
ans = 0

for i in range(N):
    a, b = table[i]
    if a > M:
        break
    if count[a-1] == M-a+1 or cnt == M:
        continue
    ans += b
    cnt += 1
    count[a-1] += 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n , m = list(map(int, input().split(' ')))
s = []
for i in range(n):
    a, b = list(map(int, input().split(' ')))
    s.append([b,a])
s.sort(reverse = True)
i = 0
result = 0
while m > 0 and i < n:
    if m >= s[i][1]:
        result += s[i][0]
        m -= 1
        i += 1
    else:
        i += 1
print(result)

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)
AB.append((0, 0))

ans, idx, lAB = 0, 0, len(AB)
for i in range(M, 0, -1):
    while AB[idx][0] > i and idx < lAB:
        idx += 1
    ans += AB[idx][1]
    if idx < lAB - 1:
        idx += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M = map(int,input().split())

AB = []
for i in range(N):
    Ai,Bi = map(int,input().split())
    AB.append([Ai,Bi])

AB.sort(key=itemgetter(1),reverse=True)
AB.sort(key=itemgetter(0))
from heapq import heappush, heappop
hq = []
i = 0
now = 1
ans = 0
while True:
    if i != N:
        if AB[i][0] == now:
            heappush(hq,-AB[i][1])
            i += 1
            continue
        else:
            if len(hq) == 0:
                now += 1
                continue
            ans -= heappop(hq)
            now += 1
    else:
        if now <= M:
            if len(hq) == 0:
                break
            ans -= heappop(hq)
            now += 1
        else:
            break


print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab1 = sorted(ab, key=lambda x: [x[0], x[1]], reverse =True)
a1 = [i[0] for i in ab]
b1 = [i[1] for i in ab]

limit = m
ans1 = 0

for idx, time in enumerate(a1):
        if time <= limit:
            ans1 += b1[idx]
            limit -=1

ab2 = sorted(ab, key=lambda x: [x[1], x[0]], reverse =True)
a2 = [i[0] for i in ab2]
b2 = [i[1] for i in ab2]

limit = m
ans2 = 0

for idx, time in enumerate(a2):
        if time <= limit:
            ans2 += b2[idx]
            limit -=1

print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A, B = map(int, input().split())
    if A > M:
        pass
    else:
        A_B.append((A,B))
# print(A_B)
if len(A_B) == 0:
    print(0)
else:
    # print(sorted(A_B, key=lambda x: x[1]))
    A_B = sorted(A_B, key=lambda x: x[0])
    A_B = sorted(A_B, key=lambda x: x[1])[::-1]
    # print(A_B)
    # lim = 0
    reward = 0
    cnt = M
    for i in range(len(A_B)):
        # if  cnt - A_B[i][0] >= 0:
        #     reward += A_B[i][1]
        # else:
        for j in range(i, len(A_B)):
            if cnt - A_B[j][0] >= 0:
                reward += A_B[j][1]
                break
        cnt -= 1
            
    print(reward)

Submission status: Wrong Answer

Solution code:
n, m = [int(s) for s in input().split()]
ab = [tuple(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: x[1])[::-1]

ans = 0
for d in range(1, m+1)[::-1]:
  for i, (a, b) in enumerate(ab):
    if a <= d:
      ans += b
      ab.pop(i)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M= list(map(int, input().split()))
li=[]
for i in range(N):
    li.append(list(map(int, input().split())))
li.sort(key=lambda x:(-x[1],x[0]))
money=0
hosei=0
for j in range(M):
    for i in range(N-hosei):
        if M>=j+li[i][0]:
            tmp=li.pop(i)
            hosei+=1
            money+=tmp[1]
            break
print(money)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def get_true(ls_A, thresh, inf):
    y = inf
    for i, x in enumerate(ls_A):
        if x <= thresh:
            y = i
            break
        else:
            pass
    return y

N, M = list(map(int, input().split()))
inf = 2 * M
A = [0] * N
B = [0] * N
ans = 0

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

C = sorted(zip(A, B), key=itemgetter(0))
A, B = zip(*C)
A = list(A[::-1])
B = list(B[::-1])


while 1:
    ind = get_true(A, M, inf)
    A = A[ind:]
    B = B[ind:]
    if B == []:
        break
    id_max = B.index(max(B))
    ans += B[id_max]
    del(A[id_max])
    del(B[id_max])
    M -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())

tasks=[]
for i in range(n):
  a,b = map(int, input().split())
  tasks.append((b,a))

tasks.sort(reverse=True)
#print(tasks)
ans=0
for i in range(m):
  for j in range(n-i):
    if m-i>=tasks[j][1]:
      ans+=tasks[j][0]
      tasks.pop(j)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,M = inputMap()
	ab = []
	cnt = {}
	for i in range(N):
		a,b = inputMap()
		if a in cnt:
			cnt[a] += 1
		else:
			cnt[a] = 1
		ab.append((a,b))

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

	ans = 0
	#print(aa)
	for i in range(M,0,-1):
		#print(i)
		for j, val in enumerate(aa):
			a,b = val
			#print("{} {}".format(a,i))
			if i >= a:
				cnt[a] -= 1
				ans += b
				aa.pop(j)
				#print(aa)
				break
			else:
				aa.pop(j)

	print(ans)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,m = [int(s) for s in input().split()]
j = []

for i in range(n):
    ai,bi = [int(s) for s in input().split()]
    j.append([ai,bi])

j = sorted(j, key=lambda x: (-x[1],-x[0]))
d = 0
r = 0
finished = False
fl = []

for i in range(n):
    if i not in fl and (d+j[i][0] <= m):
        fl.append(i)
        d += 1
        r+=j[i][1]

print(r)

Submission status: Wrong Answer

Solution code:
n, m = [int(s) for s in input().split()]
ab = [tuple(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: x[1])[::-1]

ans = 0
for d in range(1, m+1)[::-1]:
  for i, (a, b) in enumerate(ab):
    if a <= d:
      ans += b
      ab.pop(i)
      print(d, a, b, ab)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
work_list=[]
for n in range(N):
    A,B=map(int,input().split())
    work_list.append({'day':A,'price':B})
work_list.sort(key=lambda x:x['day'], reverse=True)
work_list.sort(key=lambda x:x['price'], reverse=True)

limit=M
money=0

for n in range(M+1):
    decision=False
    while not decision and len(work_list)!=0:
        work=work_list.pop(0)
        if work['day']<=limit:
            decision=True
            money+=work['price']
    limit-=1
print(money)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
A = []
B = []
parttime = []

for i in range(N):
	a, b = map(int, input().split())
	parttime.append((-b, -a))
	
parttime.sort()
index = 0
ans = 0

for day in range(M):
	flag = 0
	
	while index < N:
		if (-parttime[index][1] + day) <= M:
			ans -= parttime[index][0]
			flag = 1
			#print(parttime[index])

		index += 1
		
		if flag == 1:
			break
			
print(ans)
#print(parttime)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())

info=[]
for i in range(n):
  info.append(list(map(int,input().split())))

order=sorted(info,key=lambda x:x[1])
sum=0
for i in range(n):
  for j in range(n-i):
    if m-i-order[n-i-j-1][0]>=0:
      sum+=order[n-i-j-1][1]
      order.pop(n-i-j-1)
      break
    


print(sum)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M = map(int,input().split())
job_list = [[int(x) for x in input().split()] for i in range(N)]
job_list = sorted(job_list,key=itemgetter(1))
ans = 0
for i in range(N):
  k = len(job_list)
  for j in range(k):
    if j == len(job_list):
      break
    if i+job_list[k-1-j][0] <= M:
      ans += job_list[k-1-j][1]
      job_list.pop()
      break
    job_list.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())	
bait={}
for i in range(n):
    x,y = map(int,input().split())
    if x in bait:
        bait[x].append(y)
    else:
        bait[x]=[]
        bait[x].append(y)

ans=0
for i in range(m):
    maxtmp = 0
    for j in range(i + 1):
        if j+1 in bait and len(bait[j+1]) > 0:
            tmp = max(bait[j+1])
            if(maxtmp < tmp):
                maxtmp = tmp
                index = bait[j+1].index(tmp)
                bait[j+1].pop(index)
                break
    ans += maxtmp
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(n):
  p,q=map(int,input().split())
  a.append([q,p])
a.sort()
a.reverse()
res=0
for i in range(n):
  if i+a[i][1]<=m:
    res+=a[i][0]
print(res)

Submission status: Wrong Answer

Solution code:

N, M = tuple( map(int, raw_input().split()) )

list = []
for i in range (0, N):
    A, B = tuple( map(int, raw_input().split()) )
    list.append((B, A))

SUM = 0
for (B, A) in sorted(list, reverse=True):
    print (A, B)
    if A <= M:
        SUM += B
        M -= 1

print SUM

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={}
dayset = set()
for i in range(0,n):
    a,b=map(int,input().split())
    if a in d:
        d[a].append(b)
    else:
        d[a] = []
        d[a].append(b)
        dayset.add(a)

for k in d:
    d[k] = sorted(d[k])
    
ans = 0
for i in range(1,m+1):
    """print("i",i)
    print("ans",ans)
    print(dayset)
    print(d)"""
    daysettmp = dayset.copy()
    targetd = min(daysettmp )
    targetdset = set()
    targetdset.add(targetd) 
    daysettmp.remove(targetd)
    
    if targetd > i:
        continue
    else:
        while((targetd < i)&len(daysettmp) > 0):
                targetd = min(daysettmp)
                targetdset.add(targetd)
                daysettmp.remove(targetd)
        
    maxp = 0
    maxp_d = 0
    if len(targetdset)>0:
        for day in targetdset:
            if maxp<d[day][-1]:
                maxp = d[day][-1]
                maxp_d = day
    
    ans += maxp
    
    if maxp_d != 0:
        if len(d[maxp_d])==1:
            dayset.remove(maxp_d)
        else:
            d[maxp_d] = d[maxp_d][:-1]

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

N, M = map(int, input().split())
w = sorted([tuple(map(int, input().split())) for _ in range(N)])
days = [x[0] for x in w]
ans = 0
for i in range(M):
    c = bisect_right(days, M-i) - 1
    d = bisect_right(days, M-i-1) - 1
    if c < 0:
        break
    e = c if w[c][1] >= w[d][1] else d
    ans += w[e][1]
    del w[e]
    del days[e]

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = [int(zz) for zz in input().split()]

L = [[0] for _ in range(M)]
ans = []
for _ in range(N):
    a,b = [int(zz) for zz in input().split()]
    if a > M:
        continue
    if len(L[a-1]) > M-a:
        if min(L[a-1]) < b:
            L[a-1].remove(min(L[a-1]))
        else:
            continue

    L[a-1].append(b)
    ans.append(b)

for i in range(M):
    L[i].sort(reverse=True)

ans.sort(reverse=True)

p = min(len(ans),M)
print(sum(ans[:p]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
C = []
for _ in range(N):
    c = tuple(map(int, input().split()))
    if c[0] > M:
        continue
    C.append(c)
if len(C) == 0:
    print('0')
    exit()
C.sort(reverse=True)
ans = C[0][1]
m = M
for i in range(len(C)):
    if C[i][0] == m:
        continue
    ans += C[i][1]
    m -= 1
    if m == 0:
        break
print(ans)

Submission status: Wrong Answer

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

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

reward = 0
for i in range(1,M+1)[::-1]:
  if i < min([x[0] for x in AB]):
    break
  for n in range(len(AB)):
    if AB[n][0] <= i:
      reward += AB[n][1]
      del AB[n]
      break

print(reward)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

dp = [0 for _ in range(100000)]

def main():
    N, M = map(int, input().split())
    A_B = [list(map(int, input().split()))[::-1] for _ in range(N)]
    logging.info("Hello!")

    sorted_A_B = sorted(A_B, reverse=True)
    logging.info(sorted_A_B)


    total = 0
    for i in range(N):
        if sorted_A_B[i][1] + i <= M:
            total += sorted_A_B[i][0]


    print(total)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
box=[list(map(int,input().split())) for i in range(n)]
day={}
for i in box:
    if i[0] in day:
        day[i[0]] +=[i[1]]
    else:
        day[i[0]]=[i[1]]
count=0
point=0

while point<m:
    score=[0,0]
    for v,t in day.items():
        if v+point<=m:
            if len(day[v])>0:
                if max(t)>score[1]:
                    score=[v,max(t)]
                elif max(t)==score[1]:
                    if v>score[0]:
                        score=[v,max(t)]
    count +=score[1]
    try:
        day[score[0]].remove(score[1])
    except:break
    point +=1
print(count)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = []
for _ in range(n):
    a, b = map(int, input().split())
    heappush(jobs, (-b, -a))
ans = 0
d = 0
while m - d >= 0 and jobs:
    job = heappop(jobs)
    if job[1] + m - d >= 0:
        ans -= job[0]
        d += 1
print(ans)