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())	
bait=[]
for i in range(n):
    x,y = map(int,input().split())	
    bait.append([y, x])

bait.sort()

bait.reverse()

ans=0
for i in range(m):
    for j in range(len(bait)):
        if bait[j][1] <= m:
            ans += bait[j][0]
            bait.pop(j)
            break
    m -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[]
q=0
for i in range(n):
    p=[int(j) for j in input().split()]
    q=max(q,p[0])
    ab.append(p)
from operator import itemgetter

ab.sort(key=itemgetter(0))
ab.reverse()
ab.sort(key=itemgetter(1))
ab.reverse()

k=0
ans=0
l=[0 for i in range(q+1)] 
for i in range(n):
    if l[ab[i][0]]<m-ab[i][0]+1:
        ans+=ab[i][1]
        l[ab[i][0]]+=1
        k+=1
    if k==m:
        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)]
AB.sort(key=lambda x: x[1])
AB.reverse()
now = 0
ans = 0
for a, b in AB:
    if now + a <= M:
        ans += b
    now += 1
print(ans)

Submission status: Wrong Answer

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

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)

count = 0
ans = 0
while m >= 0 and count < n:
    a,b = ab[count][0],ab[count][1]
    if m >= a:
        ans += b
        m -= 1
    count += 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)]

dp = [0] * (M+1)
for i in range(1, M+1):
    tmp = 0
    idx = 0
    for idxab, ab in enumerate(AB):
        if ab[0] <= i:
            if tmp < ab[1]:
                idx = idxab
            tmp = max(tmp, ab[1])
    AB[idx][1] = 0
    dp[i] = dp[i-1] + tmp

print(dp[len(dp)-1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: -x[0])
ab.sort(key = lambda x: -x[1])
q, cnt, ans = [], 0, 0
for i, (a, b) in enumerate(ab):
    if cnt == M:
        break
    if a+i <= M:
        ans += b
        cnt += 1
        heappush(q, [-a-i, a, i])
    else:
        while len(q):
            p, _a, j = heappop(q)
            if _a+i <= M and a+j <= M:
                ans += b
                cnt += 1
                break
print(ans)

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:
from operator import itemgetter
N, M = map(int, input().split())
ABs = []
for i in range(N):
  A, B = map(int, input().split())
  ABs.append((A, B))
ABs.sort(key=lambda AB: AB[0]+AB[1], reverse=True)
#print(ABs)
r = 0
m = 0
for i in range(N):
  A, B = ABs[i]
  if m+A <= M:
    r += B
    m += 1
print(r)

Submission status: Wrong Answer

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

ans = 0
BA.sort(reverse=True)
for b, a in BA:
    if a <= M:
        ans += b
        if M == 1:
            break
        M -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
lst = sorted(lst, key=lambda x: x[0], reverse=True)
lst = sorted(lst, key=lambda x: x[1], reverse=True)
d = 0
total = 0
r = []
for i in range(len(lst)):
    if d + lst[i][0] <= m:
        total += lst[i][1]
        r.append(lst[i][1])
        d += 1
print(total)

Submission status: Wrong Answer

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

ans = 0
i = 0
for m in range(M, -1, -1):
    while i < N:
        work_i_a, work_i_b = Work[i]
        if work_i_a <= m:
            ans += work_i_b
            i += 1
            break
        else:
            i += 1

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):
    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:
from heapq import heappop,heappush
L=lambda:list(map(int,input().split()))
n,m=L()
h=[]
for i in range(n):
  a,b=L()
  heappush(h,[-b,-a])
x=0
for i in range(n):
  a,b=heappop(h)
  a,b=-a,-b
  if m<b:continue
  m-=1
  x+=a
print(x)

Submission status: Wrong Answer

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

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


A.sort(reverse = True)
A.sort(key = lambda x:-x[1])

ans = 0
while(M):
    for i in range(len(A)):
        if A[i][0] <= M:
            ans += A[i][1]
            del A[i]
            break
    M -= 1

print(ans)

Submission status: Wrong Answer

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

t = 0
res = 0
for b, a in L:
    if t + a > M:
        continue
    t += 1
    res += b
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC137 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
ab = [LI() for _ in range(n)]
ab = sorted(ab,key = lambda x:(-x[1],-x[0]))
for i in range(n):
    ab[i].append(i)
ans = 0
for i,j,k in ab:
    if i + k <= m:
        ans += j
    else:
        continue
print(ans)

Submission status: Wrong Answer

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

from heapq import *

que = []
for a, b in items:
    if a > M:
        continue
    else:
        que.append([-b, -a])

heapify(que)

day = 1
ans = 0
while len(que) > 0 and day <= M:
    q = heappop(que)
    if -q[1] -1+ day <= M:
        ans += -q[0]
        day += 1
        # heappush(que, q)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[]
q=0
for i in range(n):
    p=[int(j) for j in input().split()]
    q=max(q,p[0])
    ab.append(p)
from operator import itemgetter

ab.sort(key=itemgetter(0))
ab.reverse()
ab.sort(key=itemgetter(1))
ab.reverse()

ans=0
l=[0 for i in range(q+1)] 
for i in range(min(n,m)):
    if l[ab[i][0]]<m-ab[i][0]+1:
        ans+=ab[i][1]
        l[ab[i][0]]+=1
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)
AB.sort(key=lambda x:x[1],reverse=True)
nokori = M
i = 0
ans = 0
while i < N and nokori > 0:
    a,b = AB[i]
    if nokori >= a:
        ans += b
        nokori -= 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

N, M = map(int, input().split())
q = list()
for _ in range(N):
    A, B = map(int, input().split())
    deadline = M - A
    reward_inv = -B
    heappush(q, (reward_inv, deadline))

ans = 0
for day in range(M + 1):
    if len(q) == 0:
        print(ans)
        exit(0)
    reward_inv, deadline = heappop(q)
    while day > deadline:
        if len(q) == 0:
            print(ans)
            exit(0)
        reward_inv, deadline = heappop(q)
    ans += -reward_inv

print(ans)

Submission status: Wrong Answer

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

ab_list = [ab for ab in ab_list if ab[0] <= M]

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

ans = 0

i = 0
while len(ab_list) > 0 and i <= M:

    if i + ab_list[0][0] <= M:
        ans += ab_list[0][1]
        i += 1
    ab_list.pop(0)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
c={}
for _ in range(n):
  a,b=[int(i) for i in input().split()]
  if a in c:
    c[a].append(b)
  else:
    c[a]=[b]
k=0
l=[]
for i in range(m+1):
  if i in c:
    j=list(reversed(sorted(c[i])))
    if l:
      if j[0]>l[0]:
        k+=j[0]
        if len(j)>1:
          l=list(reversed(sorted(l+j[1:])))
      else:
        k+=l[0]
        l=list(reversed(sorted(l[1:]+j)))
    else:
      k+=j[0]
      j=j[1:]
  else:
    if l:
      k+=l
      l=l[1:]
print(k)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
X=[]
for i in range(N):
    a,b=map(int,input().split())
    X.append((a,b))
X.sort(key=lambda x:(-x[1],-x[0]))
ans=0
Y=[]
k=0
for i in range(N):
    a,b=X[i]
    if a+k<=M:
        Y.append((a,b))
        k+=1
ans=0
for i in Y:
    a,b=i
    ans+=b
print(ans)

Submission status: Wrong Answer

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

task.sort(reverse=True, key=lambda x: (x[1], x[0]))
ans = 0
nokori = M
for t in task:
    if t[0] <= nokori:
        ans += t[1]
    nokori -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l = [[int(a) for a in input().split()] for i in range(N)]
l = sorted(l, key=lambda x: (-1*x[1], -1*x[0]))
ans = 0
j = 0
for i in range(1, M+1):
    a, b = l[j]
    if a + i <= M + 1:
        ans += b
        j += 1
    if j == N - 1:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,reverse=True,key=lambda x:x[1])
arr=sorted(arr,reverse=True,key=lambda x:x[0])
q=[]
tmp=0
cnt=0
for a,b in arr:
  if tmp!=a:
    tmp=a
    cnt=0
  if m-tmp<cnt:
    continue
  heapq.heappush(q,-b)
  cnt+=1
ans=0
cnt=0
while len(q)!=0:
  if cnt>=m:
    break
  tmp=heapq.heappop(q)
  ans-=tmp
  cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
# n = int(input())
# A = list(map(int, input().split()))
N, M = map(int, input().split())

jobs = []

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

jobs.sort(reverse=True)

# print(jobs)

res = 0
current = 0

for i in range(0, M):
    while current < N and i + jobs[current][1] > M:
        current += 1
    if current >= N:
        break

    res += jobs[current][0]
    # print(current)
    # print(jobs[current])
    current += 1

print(res)

Submission status: Wrong Answer

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

arr.sort(key=lambda x:[x[1],x[0]])
# print(arr)
ind = n-1
ans = 0
for i in range(m):
    lest = m-i
    while True:
        if arr[ind][0] <= lest:
            ans += arr[ind][1]
            ind -=1
            break
        else:
            ind -= 1
            if ind < 0:
                break
    if ind < 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
A=[]
for i in range(n):
  a,b=map(int,input().split())
  A.append([a,b,a+b])
A.sort(key=lambda x:(x[2],x[1],x[0]), reverse=True)
ans=0
for i in range(n):
  a,b,c=A[i]
  if a<=m:
    ans+=b
    m-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

A = np.array(A)
B = np.array(B)
ind = np.argsort(A)[::-1]
A = A[ind]
B = B[ind]

while (A <= M).any():
    ind = A <= M
    A = A[ind]
    B = B[ind]
    id_max = B.argmax()
    ans += B[id_max]
    A[id_max] = M + 1
    M -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

P = {}
for a, b in AB:
    if a <= M:
        if not a in P.keys():
            P[a] = [b]
        else:
            P[a].append(b)
Q = []
for k, v in P.items():
    v.sort(reverse=True)
    Q.extend(v[:M-k+1])
Q.sort(reverse=True)
print(sum(Q[:M]))

Submission status: Wrong Answer

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

result = 0
for i in range(M, -1, -1):
  for j in range(len(info)):
    if info[j][0] <= i:
      #print(info[j], i)
      result += info[j][1]
      info.pop(j)
      break
print(result)

Submission status: Wrong Answer

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

_d = {i:set() for i in range(M+1)}
for a,b in AB:
  _d.setdefault(a, set()).add(b)
  
import heapq

ans = 0
hp = []

for i in range(1, M+1):
  for b in _d[i]:
    heapq.heappush(hp, -b)
  if hp:
    ans += -heapq.heappop(hp)

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)

ans = 0
day = m
for i in range(min(n,m)):
    if day == 0:
        break
    a = tasks[i][1]
    b = tasks[i][0]
    if a <= day:
        ans += b
    day -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
L=lambda:list(map(int,input().split()))
n,m=L()
c=[]
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:
  if m<i[1]:continue
  m-=1
  a+=i[0]
print(a)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
A=[]
for i in range(n):
  a,b=map(int,input().split())
  A.append([a,b,a+b])
A.sort(key=lambda x:(x[2],x[0],x[1]), reverse=True)
ans=0
for i in range(n):
  a,b,c=A[i]
  if a<=m:
    ans+=b
    m-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
c={}
for _ in range(n):
  a,b=[int(i) for i in input().split()]
  if a in c:
    c[a].append(b)
  else:
    c[a]=[b]
k=0
l=0
for i in range(m+1):
  if i in c:
    j=list(reversed(sorted(c[i])))
    if j[0]>l:
      k+=j[0]
      if len(j)>1:
        l=max(l,j[1])
    else:
      k+=l
      l=j[0]
  else:
    k+=l
    l=0
print(k)

Submission status: Wrong Answer

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

result = 0
for i in range(M, -1, -1):
  for j in range(len(info)):
    if info[j][0] <= i:
      #print(info[j], i)
      result += info[j][1]
      info.pop(j)
      break
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
c={}
for _ in range(n):
  a,b=[int(i) for i in input().split()]
  if a in c:
    c[a].append(b)
  else:
    c[a]=[b]
k=0
l=0
for i in range(1,m+1):
  if i in c:
    j=list(reversed(sorted(c[i])))
    if j[0]>l:
      k+=j[0]
      if len(j)>1:
        l=max(l,j[1])
    else:
      k+=l
      l=j[0]
  else:
    k+=l
    l=0
print(k)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np

# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    # divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            # divisors.append(i)
            return i
            # if i != n // i:
            #     divisors.append(n//i)


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n, m = ip.IL()
    ab = ip.SILS(n)
    id.S(ab, 1, 0)
    id.S(ab, 1, 1)
    # print(ab)
    ans = 0
    day = 0
    for x in ab:
        if x[0] <= m - day:
            ans += x[1]
            day += 1
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np

# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    # divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            # divisors.append(i)
            return i
            # if i != n // i:
            #     divisors.append(n//i)


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n, m = ip.IL()
    ab = ip.SILS(n)
    id.S(ab, 1, 1)
    # id.S(ab, 0, 1)
    hantei = [False for _ in range(m)]
    # print(ab)
    ans = 0
    day = 1
    for x in ab:
        try:
            if not hantei[x[0]-1]:
                # print(x)
                ans += x[1]
                day += 1
                hantei[x[0]-1] = True
        except:
            pass
        # if day == m:
            # break
    # print(hantei)
    print(ans)


main()

Submission status: Wrong Answer

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

ans = 0
for d in range(M):
    if not AB: break
    while AB:
        a,b = AB.pop()
        if d+a <= M:
            ans += b
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
ls = [[int(i) for i in input().split()] for j in range(n)]
ls.sort(reverse = True,key = lambda x:(x[1],x[0]))

ans = 0
for i in range(n):
    if m >= ls[i][0]:
        ans += ls[i][1]
        m -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
work = [list(map(int, input().split())) for _ in range(n)]
work.sort(key=lambda x: (x[1], x[0]), reverse=True)

ans = 0
idx = 0
for day in range(m+1):
    while idx < n:
        a, b = work[idx]
        if day + a <= m:
            ans += b
            idx += 1
            break
        else:
            idx += 1
    if idx >= n:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=itemgetter(1))
l.reverse()
ct=0
day=0
for i in range(n):
  if m-day>=l[i][0]:
    ct+=l[i][1]
    day+=1
print(ct)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
L=lambda:list(map(int,input().split()))
n,m=L()
c=[]
for i in range(n):
  a,b=L()
  c.append([b,a])
c.sort(reverse=1)
a=0
for i in range(n):
  if c[i][1]<=m:a+=c[i][0];m-=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,M = i_map()
    l = [i_list() for _ in range(n)]
    l.sort(reverse = True)

    dp = [0]*(M+1)
    for i,k in l:
        if i > M:
            continue
        m = min(dp[:(-i)])
        d = dp.index(m)
        if k > m:
            dp[d] = k
    print(sum(dp))





if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq

n,m=map(int,input().split())
mm=10**5+5
c=[[0] for i in range(mm)]

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

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  h+=list(map(lambda x:-x, c[d]))
  heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
from collections import deque

n,m=map(int,input().split())
dic=dd(list)
for i in range(1,m+1):
    dic[i]=[0]


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


for k,v in dic.items():
    dic[k]=deque(sorted(dic[k],reverse=True))

#print(dic)

ans=0
max2nd=[0]
for i in reversed(range(m)):
    d=m-i
    a=dic[d][0]
    max2nd=deque(sorted(max2nd,reverse=True))
    b=max2nd[0]
    if a>=b:
        ans+=dic[d].popleft()
        if len(dic[d])==0: dic[d]=[0];
    else:
        ans+=max2nd.popleft()
        if len(max2nd)==0: max2nd=[0];
    max2nd+=dic[d]
        

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
from collections import deque

n,m=map(int,input().split())
dic=dd(list)
for i in range(1,m+1):
    dic[i]=[0]*m

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


for k,v in dic.items():
    dic[k]=deque(sorted(dic[k],reverse=True))

#print(dic)

ans=0
max2nd=[0]*m
for i in reversed(range(m)):
    d=m-i
    a=dic[d][0]
    max2nd=deque(sorted(max2nd,reverse=True))
    b=max2nd[0]
    if a>=b:
        ans+=dic[d].popleft()
    else:
        ans+=max2nd.popleft()
    max2nd+=dic[d]
        

print(ans)