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:
"""
AtCoder
    :author: vierbein
"""
from __future__ import absolute_import, division, print_function

# import itertools as it
# import collections
import sys


def pp(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


N, M = map(int, input().split())
pairs = [[int(s) for s in input().split()] for _ in range(N)]
pairs = [(b, M - a) for (a, b) in pairs]
pairs = sorted(pairs, key=lambda tup: (-tup[0], tup[1]))
# pp(pairs)

res = 0
idx = 0
for (point, remaining) in pairs:
    if idx <= remaining:
        res += point
        idx += 1

    if idx == N:
        break

print(res)

Submission status: Wrong Answer

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


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

ab_list = sorted(ab_list, reverse=True)

monies = [0 for i in range(m + 1)]
d2c = collections.Counter()

for money, day in ab_list:
  try:
    idx = monies.index(0, day + d2c[day])
  except:
    continue
  monies[idx] = money
  d2c[day] += 1
# print(monies)
print(sum(monies))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
ba = []
for i in range(N):
    a, b = map(int, input().split())
    ba.append([b, a])
ba.sort(reverse=True)

total = 0
limit = N
for i in range(N):
    if i + ba[i][1] > limit:
        break
    else:
        total += ba[i][0]
print(total)

Submission status: Wrong Answer

Solution code:
import bisect
n, m = [int(i) for i in input().split()]
d = []
for i in range(n):
    a, b = [int(_) for _ in input().split()]
    d.append([a, b])

d.sort(reverse=True)
l = [-1 for i in range(m+1)]
for i in range(n):
    if d[i][0] <= m and l[d[i][0]] == -1:
        l[d[i][0]] = i
ans = 0
cand = []
key = []
for i in range(1, m+1):
    idx = bisect.bisect_left(cand, d[l[i]][1])
    if l[i] != -1:
        idx = bisect.bisect_left(cand, d[l[i]][1])
        cand.insert(idx, d[l[i]][1])
        key.insert(idx, i)

    if len(cand) > 0:
        ans += cand[-1]
        if l[key[-1]] + 1 < n and d[l[key[-1]]+1][0] == d[l[key[-1]]][0]:
            idx = bisect.bisect_left(cand, d[l[key[-1]]+1][1])
            cand[-1] = d[l[key[-1]]+1][1]
            l[key[-1]] += 1
        else:
            del cand[-1]
            del key[-1]

print(ans)

Submission status: Wrong Answer

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

ab = []

for _ in range(N):
    ab.append(tuple(map(int, input().split())))


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

ans = 0


for i in range(1, N+1):
    
    while l:
        a, b = l.pop()
        
        if i + a-1 <= M:
            ans += b
            break
    
    if not l:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from collections import deque
N, M = map(int, input().split())
ABs = [list(map(int, input().split())) for _ in range(N)]

lists = [[] for _ in range(10**5 + 1)]
availables = deque()
for A, B in ABs:
    bisect.insort(lists[A], B)

ans = 0
for i in range(1, M + 1):
    tmp = []
    while lists[i] or availables:
        if not lists[i]:
            tmp.extend(reversed(availables))
            break
        elif not availables:
            tmp.extend(reversed(lists[i]))
            break
        if availables[-1] < lists[i][-1]:
            tmp.append(availables.pop())
        else:
            tmp.append(lists[i].pop())
    availables = deque(reversed(tmp))
    if availables:
        ans += availables.pop()

print(ans)

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):
    k += 1
    for j in range(min(i+1,len(salary_list[i]))):
        if k > 0:
            ans_list.append(salary_list[i][j])
            k -= 1

ans_list = sorted(ans_list,reverse = True)

print(sum(ans_list[:m]))

Submission status: Wrong Answer

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

def sol():
    n,m=map(int,input().split())
    d=[]
    ans=[0]*(m+1)
    t=0
    x,y=1,m
    for i in range(n):
        a,b=map(int,input().split())
        d.append((b,a))
    d.sort(reverse=True)
    for bb,aa in d:
        if max(x,aa)==y:
            ans[y]=1
            t+=bb
            y-=1
        else:
            for j in range(max(x,aa),y+1):
                if ans[j]==0:
                    ans[j]=1
                    t+=bb
                    #if j==x: x+=1
                    #if j==y: y-=1
                    break

    print(t)

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

Solution code:
a,b=map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(a)] 
e.sort(reverse=True)

count = 0

for i in range(a):
    if e[i][0] <= b:
        b -= 1
        count += e[i][1]
        
print(count)

Submission status: Wrong Answer

Solution code:
n,m = input().split()
N,M = int(n),int(m)
p = 0
box = []
for i in range(N):
  box.append([int(s) for s in input().split()])
box.sort(key=lambda x:-x[1])
box.sort(key=lambda x:-x[0])

for k in range(M):
  
  for i,j in enumerate(box):
    if j[0] <= M:
      p += j[1]
      break
    
  M -= 1
  
print(p)

Submission status: Wrong Answer

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

import sys
from operator import itemgetter, attrgetter

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])
    
    ab = []
    for i in range(1, n+1):
        tokens = lines[i].split(" ")
        a = int(tokens[0])
        b = int(tokens[1])
        ab.append((a, b))

    return (n, m, ab)


def solve(n, m, ab):

    sorted_ab = list(sorted(ab, key=itemgetter(1, 0), reverse=True))

    remained_day = m
    total = 0
    for i in range(n):
        a = sorted_ab[i][0]
        if remained_day >= a:
            b = sorted_ab[i][1]
            total = total + b
            if debug:
                log("i=%d, remained_day=%d, a=%d, b=%d, total=%d" % (i, remained_day, a, b, total))
            remained_day = remained_day - 1

    return total


def main():
    # 出力

    print("%s" % solve(*parse_input()))
    #solve(*parse_input())

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(str,input().split())) for l in range(n)]
ab_s=sorted(ab,key=lambda x:x[1],reverse=True)
ct=0
j=0
t=0
for i in range(int(m)):
    if j>=int(n):break
    if t+i>int(m):break
    if m>=int(ab_s[j][0]) and j==0:
        ct+=int(ab_s[j][1])
        #print(ct,ab_s[j],1)
        t+=1
        j+=1
    if m>=int(ab_s[j][0]) and j>0 and int(ab_s[j][0])!=int(ab_s[j-1][0]):
        ct+=int(ab_s[j][1])
       # print(ct,ab_s[j],1)
        t+=1
        j+=1
    if m>=int(ab_s[j][0]) and j>0 and int(ab_s[j][0])==int(ab_s[j-1][0]):
        if int(ab_s[j][0])+i+1<=m:
            ct+=int(ab_s[j][1])
          #  print(ct,ab_s[j],1)
            t+=1
            j+=1
        else:j+=1
    else:break
print(ct)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    Q = defaultdict(list)
    Q2 = defaultdict(list)
    Q3 = []
    for a, b in zip(A, B):
        heapq.heappush(Q[a], -b)
    
    for a in Q.keys():
        rank = M-a+1
        for i, b in enumerate(Q[a]):
            if i >= rank:
                break
            score = i + a
            heapq.heappush(Q2[score], b)

    res = 0
    for i in range(1, M+1):
        Q3 = list(heapq.merge(Q3, Q2[i]))
        if len(Q3) == 0:
            continue
        b = heapq.heappop(Q3)
        res -= b

    print(res)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ab = []

for _ in range(N):
    ab.append(tuple(map(int, input().split())))


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

ans = 0

print(';;;;;;;')

for i in range(1, N+1):
    
    while l:
        a, b = l.pop()
        print(a, b)
        
        if i + a-1 <= M:
            ans += b
            break
    
    if not l:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
AB = []
for n in range(N):
    temp = [int(i) for i in input().split()]
    if temp[0] <= M:
        AB.append(temp)
from collections import deque
#works = sorted(AB,key=lambda x:(-x[1],x[0],))
works = deque(AB)
work_schedule = [0]*M
for w in range(len(works)):
    work = works.popleft()
    if work[0] > M:
        pass
    else:
        cnt = 0
        while True:
            if (work[0]-1+cnt) >= M:
                break
            elif work_schedule[work[0]-1+cnt]  == 0:
                work_schedule[work[0]-1+cnt] = work[1]
                break
            else:
                cnt+=1
print(sum(work_schedule))

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,key= lambda x:x[1],reverse=True)
reward = 0
AB = sorted(AB[:M],reverse = True) + AB[M:]
while(1):
    if M == 0 or len(AB) == 0:
        break
    if AB[0][0] >= M:
        AB.pop(0)
        continue
    else:
        reward += AB[0][1]
        AB.pop(0)
        M = M - 1

print(reward)

Submission status: Wrong Answer

Solution code:
N,M =map(int,input().split())
money_day_list = []
for i in range(N):
    day,money = map(int,input().split())
    money_day_list.append([money,day])
money_day_list.sort(reverse = True)
choise = money_day_list[0:M]
cnt = 0
for m in range(M,0,-1):
#    print(choise)
    m_list = [1]*10000000
    ok = 1
    while len(m_list) <= ok:
        m_list = []
        for c in choise:
            if c[1] == m:
                m_list.append[c]
        if len(m_list) == 0:
            ok += 1
        if len(m_list) != ok:
            choise.remove(m_list[-1])
            if M+cnt > N-1:
                break
            choise.append(money_day_list[M+cnt])
            cnt += 1
ans = 0
for c in choise:
    ans += c[0]
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n, m = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n)]
abab = sorted(sorted(abab, key=itemgetter(0), reverse=True), key=itemgetter(1), reverse=True)

gyara = 0
i = 1
for a, b in abab :
    if m+1-i >= a :
        gyara += b
        i += 1

print(gyara)

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

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x != 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

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])
f = [0] * M
cnt, ans = 0, 0
bit = BIT(M+1)
for a, b in ab:
    if M-a >= 0 and bit.sum(M-a+1) <= M-a:
        ans += b
        cnt += 1
        if cnt == M:
            break
        bit.add(M-a+1, 1)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(N):
    temp = list(map(int, input().split()))
    AB.append(temp)
AB = sorted(AB, reverse=True)
AB = sorted(AB, reverse=True, key=lambda x: x[1] )
#print(AB)
Day = 0
ans = 0
for i in AB:
    if i[0] + Day <= M:
        ans += i[1]
        Day +=1

print(ans)

Submission status: Wrong Answer

Solution code:
def max_acc(m, alist):
    max = 0
    i = -1
    id = -1
    for index, a in enumerate(alist):
        if a[0] <= m:
            if a[1] >= max:
                if a[0] >= id:
                    max = a[1]
                    i = index
                    id = a[0]
            else:
                break
    return i

n, m = [ int(x) for x in input().split()]
a = []
for i in range(n):
    a.append([int(x) for x in input().split()])
a = sorted(a, key=lambda x: x[0], reverse=True)
a = sorted(a, key=lambda x: x[1], reverse=True)
total = 0
for i in reversed(range(1, m +1)):
    index = max_acc(i, a)
    if index != -1:
        item = a.pop(index)
        total += item[1]
print(total)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
li = [tuple(map(int, input().split())) for i in range(N)]
M1 = M2 = M
ans = 0
ans2 = 0

li.sort(key=lambda x: x[1], reverse=True)
li.sort(key=lambda x: x[0], reverse=True)
for i in li:
    if i[0] <= M1:
        ans += i[1]
        M1 -= 1
li.sort(key=lambda x: x[1], reverse=True)
for i in li:
    if i[0] <= M2:
        ans2 += i[1]
        M2 -= 1
print(max(ans, ans2))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
data = [[int(e) for e in input().split()] for _ in range(n)]
t = [0] * (m + 1)
for i in range(n):
  a, b = data[i]
  for j in range(m, -1, -1):
    if j + a <= m:
      t[j + 1] = max(t[j + 1], t[j] + b)
print(max(t))

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]))
ans = 0
for i in range(m):
    for a,b in ab:
        if a + i <= m:
            ans += b
            ab.remove([a,b])
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(str,input().split())) for l in range(n)]
ab_s=sorted(ab,key=lambda x:x[1],reverse=True)
ct=0
j=0
t=0
for i in range(int(m)):
    if j>=int(n):break
    if t+i+1>int(m):break
    if m>=int(ab_s[j][0]) and j==0:
        ct+=int(ab_s[j][1])
        t+=1
        j+=1
    if m>=int(ab_s[j][0]) and j>0 and int(ab_s[j][0])!=int(ab_s[j-1][0]):
        ct+=int(ab_s[j][1])
        #print(ct,ab_s[j],1)
        t+=1
        j+=1
    if m>=int(ab_s[j][0]) and j>0 and int(ab_s[j][0])==int(ab_s[j-1][0]):
        if int(ab_s[j][0])+i+1<=m:
            ct+=int(ab_s[j][1])
            t+=1
            j+=1
        else:j+=1
    else:break
print(ct)

Submission status: Wrong Answer

Solution code:
import numpy as np
[N,M] = list(map(int,input().split()))

A = []
B = []
d = [[] for i in range(10**4)]
for i in range(N):
    [An,Bn] = list(map(int,input().split()))
    d[Bn-1].append(An)
for i in range(10**4):
    d[i].sort()

output = 0

t = M
now = len(d)-1
flag = 0

while flag ==0:
    if len(d[now])==0:
        now += -1
    elif len(d[now])>0:
        if d[now][-1]<=t:
            output += (now+1)
            t += -1
            d[now].pop()
        elif d[now][-1]>t:
            d[now].pop()
    if (now<0)or(t<=0):
        flag = 1

print(output)

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
a_list = []
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        a_list.append([a, b])
a_list = sorted(a_list, key=lambda x: (x[0], -x[1]))
a_list_1 = [aa[0] for aa in a_list]
a_list_2 = [aa[1] for aa in a_list]
ans = 0
for i in range(m):
    k = bisect.bisect_right(a_list_1, m - i) - 1
    a_list_1 = a_list_1[:k + 1]
    a_list_2 = a_list_2[:k + 1]
    if k >= 0:
        l = len(a_list_2) - list(reversed(a_list_2)).index(max(a_list_2)) - 1
        if l < len(a_list_2):
            if a_list_1[l] <= m - i:
                ans += a_list_2[l]
                del a_list_1[l], a_list_2[l]
    else:
        print(ans)
        exit()
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[0],reverse=True)
ab.sort(key=lambda x:x[1],reverse=True)
l=[m-i for i in range(m)]
l.insert(0,0)
x=[]
for i in range(n):
    if ab[i][0]<=m and l[ab[i][0]]>0:
        x.append(ab[i])
        l[ab[i][0]]-=1
    else:
        continue
ans=0
ll=[m-i for i in range(m)]
ll.insert(0,0)
h=len(x)
g=m
for i in range(h):
    if  g>0 and ll[x[i][0]]>0:
        ans+=x[i][1]
        g-=1
        ll[:m-i]=list(map(lambda x:x-1,ll[:m-i]))
        if x[i][0]>=m-i:
            ll[x[i][0]]-=1
print(ans)

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
ans = 0
cnt = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    n, m = list(map(int, input().split()))
    ab = sorted(list(list(map(int, input().split())) for _ in range(n)), key=lambda x: (-x[1], -x[0]))
    now, earn = 0, 0
    for days, value in ab:
        if now + days <= m:
            earn += value
            now += 1
    return earn


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

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

ab = [list(map(int, input().split())) for i in range(n)]
ab = list(sorted(ab, reverse=True))

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

a=[0 for i in range(m)]
ans=0
for i in range(n):
  for j in range(l[i][0]-1,m):
    if a[j]<l[i][1]:
      a[j]=l[i][1]
      break

#print(a)
print(sum(a))

Submission status: Wrong Answer

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

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

ans = 0
days = M
ab_i = ab
for i in range(days):
    ab_i = [e for e in ab_i if e[0] <= M]
    if(len(ab_i) == 0):
        break
#    print("sortmae M:"+str(M)+" i:"+str(i)+" a_i[0]:"+str(ab_i[0]) + " len:" + str(len(ab_i)))
    ab_i.sort(key=lambda x:(x[1],x[0]),reverse=True)
    ans = ans + ab_i[0][1]
    del ab_i[0]
    M =M - 1
#    if(len(ab_i) > 0):
#        print("sortgo  M:"+str(M)+" i:"+str(i)+" a_i[0]:"+str(ab_i[0]) + " len:" + str(len(ab_i)))

print(ans)

Submission status: Wrong Answer

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

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

counts = [0]*(M+1)
num = 0
ans = 0
i = 0
while num < M and i < N:
    a = tmp[i][0]
    b = tmp[i][1]
    if a > M:
        break
    if counts[a] < (M - a + 1):
        counts[a] += 1
        ans += b
        num += 1
    i += 1
print(ans)

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[0],-x[1]))
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:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline--------------------------------------------
    N,M = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    AB.sort(key = lambda x:x[0],reverse = True)
    AB.sort(key = lambda x:x[1],reverse = True)
    ans = 0
    accum = 0
    for i in range(N):
            if accum+AB[i][0] > M:
                pass
            else:
                ans += AB[i][1]
                accum += 1
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0],reverse=True)
ab.sort(key=lambda x:x[1],reverse=True)
day=m
money=0
cnt=0
for s in ab:
  if s[0]<=day:
    money+=s[1]
    day-=1
    if day==0:
      break
print(money)

Submission status: Wrong Answer

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

d = defaultdict(list)

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

works = []
for k in range(M, 0, -1):
    if M-k+1 >= 1:
        works.extend(d[k][:M-k+1])
        works = sorted(works, reverse=True)
        works = works[:M-k+1]
        # print(works)

print(sum(works))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
li = [tuple(map(int, input().split())) for i in range(N)]
ans = 0
ans2 = 0

li.sort(key=lambda x: x[1], reverse=True)
li.sort(key=lambda x: x[0], reverse=True)
for i in li:
    if i[0] <= M:
        ans += i[1]
        M -= 1
li.sort(key=lambda x: x[1], reverse=True)
for i in li:
    if i[0] <= M:
        ans2 += i[1]
        M -= 1
print(max(ans, ans2))

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 = []

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:
N, M = map(int, input().split())  # N件のアルバイト, M日後までの報酬
hoge = M  # M日後まではもらえる
arubaito = [list(map(int, input().split())) for _ in range(N)]  # A日後に, B円報酬がもらえる。

arubaito = sorted(arubaito, key=lambda x: (x[1], x[0]), reverse=True)  # 報酬順にソート
ans = 0
# print(arubaito)
for i in range(N):
    # print("i = ", i, "m = ", hoge)
    if hoge >= arubaito[i][0]:
        ans += arubaito[i][1]
        hoge -= 1  # 日雇いアルバイトしたなら日付を進める

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: (x[0], x[1]))
A, B = [0], [0]
for i in range(N):
    A.append(X[i][0])
    B.append(X[i][1])
print(A, B)

ans = 0
index_upper = 1
for k in range(1, M + 1):
    Ak = [a for a in A if a <= k]
    index_upper = len(Ak)
    res = max(B[:index_upper])
    if res != 0:
        A.remove(A[B.index(res)])
        B.remove(res)
    ans += res
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.sort(key=lambda x:x[0],reverse=True)
ab.sort(key=lambda x:x[1],reverse=True)
print(ab)
day=m
money=0
cnt=0
for s in ab:
  if s[0]<=day:
    money+=s[1]
    print(s[0],s[1])
    day-=1
    if day==0:
      break
print(money)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
l = list(map(int,input().split()))
N = l[0]
M = l[1]

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

ans = 0
days = M
ab_i = ab
for i in range(days):
    ab_i = [e for e in ab_i if e[0] <= M]
    if(len(ab_i) == 0):
        break
    print("sortmae M:"+str(M)+" i:"+str(i)+" a_i[0]:"+str(ab_i[0]) + " len:" + str(len(ab_i)))
    ab_i.sort(key=lambda x:(x[1],x[0]),reverse=True)
    ans = ans + ab_i[0][1]
    del ab_i[0]
    M =M - 1
    if(len(ab_i) > 0):
        print("sortgo  M:"+str(M)+" i:"+str(i)+" a_i[0]:"+str(ab_i[0]) + " len:" + str(len(ab_i)))



print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split(" "))
i=0
ss=[]
while i!=n:
    s=list(map(int,input().split(" ")))
    ss.append(s)
    i+=1
#print(ss)

ss.sort()
ss.sort(key=lambda x: x[1])
#print(ss)
i=n-1
j=0
ans=0
sans=[0]*m
#print(sans)
while j!=m:
    while True:
        try:

            k=ss[i][0]-1
            #print(k)
            while k!=m+1:
                if sans[k] == 0:
                    sans[k] = ss[i][1]
                    ans+=ss[i][1]
                    break

                k+=1
        except:
            #print("e")
            break
        i-=1
    j+=1
#print(sans)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dp = [[0 for i in range(M+1)] for j in range(N+1)]
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [-A, -B]
l.sort()
tmp = 1
for n in range(1, N+1):
    for m in range(tmp+1):
        if -l[n-1][0]  + m <= M:
            dp[n][m] = max(dp[n][m], dp[n-1][m-1] - l[n-1][1])
        dp[n][m-1] = max(dp[n][m-1], dp[n-1][m-1])
    if -l[n-1][0]  + tmp +1 <= M:
        tmp += 1
print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
#最大日数は M + M-1 + M-2 + .. + 1
#最大選択数 は M個
Y = [[] for i in range(100001)]
#Y1 = {}
for i in range(N):
    A, B = map(int,input().split())
    Y[A].append(B)


cnt = 0
C = []
for i in range(1,M+1):
    #if len(Y[i]) > 0:
    #C.extend(Y[i])
    C += Y[i]

    if len(C) > 0:
        a = max(C)
        #C.sort(reverse=True)
        cnt = cnt + a#C.pop(0)
        C.remove(a)
        #del C[0]
    if len(C) > M + 1 - i:
        C = C[:M+1-i]
print(cnt)