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 array import array
from collections import deque

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

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

day = 0
payment = 0

for a,b in AB:
    payment_day = day + a
    if payment_day <= M:
        #print('-',a,b)
        payment += b
        day += 1

#print(AB)
print(payment)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M = map(int, input().split())
List = []
for i in range(N):
    List.append([int(x) for x in input().split()])

List.sort(key=itemgetter(1))

note = []
for i in range(M+1):
    note.append(i)
    
ans = 0
m = M
i = 0
while i < min(N,M+1) and m > 0:
    if List[-i-1][0] <= m:
        if List[-i-1][0] == m:
            note[m] = 0
            ans += List[-i-1][1]
        else:
            note[List[-i-1][0]] = 0
            ans += List[-i-1][1]
    m -= 1
    i += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
Lis = [None]*N
reward = 0
for i in range(N):
    Lis[i] = list(map(int,input().split()))
Lis  = sorted(Lis, key = lambda x: x[0], reverse = True)
Lis = sorted(Lis, key = lambda x: x[1], reverse = True)
for k in range(N):
    if M - Lis[k][0] < 0:
        continue
    else:
        reward += Lis[k][1]
        M -= 1
print(reward)

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[0], x[1]), reverse=True)
#print(info)

result = 0
for j in range(len(info)):
    if info[j][0] <= M:
      #print(info[j], i)
      result += info[j][1]
      M -= 1
    if M == 0:
      break
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]))

ans = 0
c = 0
P = M
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 == P:
        break

print(ans)

Submission status: Wrong Answer

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

date = zip(a, b)
date = sorted(date)
da, db = zip(*date)

ans = 0
for d in range(1,m+1):
    #print(d)
    l =[i for i, x in enumerate(da) if x == d]
    if len(l) >= 1:
        ans += db[max(l)]

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
D = {}
for i in range(N) :
    a,b = map(int,input().split())
    if a not in D :
        D[a] = [b]
    else :
        D[a].append(b)

for k in D :
    D[k] = sorted(D[k], reverse=True)

A = []
for k in D :
    for i in range(min(len(D[k]), M-k+1)) :
        A.append(D[k][i])
A = sorted(A,reverse=True)
ans = sum(A[:M])
print(ans)

Submission status: Wrong Answer

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

ansList = [0] * M

for i in range(N):
    A, B = map(int, input().split())
    day = M - A
    if day == 0 and B > ansList[0]:
        ansList[0] = B
    elif day > 0 and day <= M-1:
        minB = min(ansList[0:day+1])
        mini = ansList.index(minB)
        if minB < B:
            ansList[mini] = B
    elif day == M:
        minB = min(ansList)
        mini = ansList.index(minB)
        if minB < B:
            ansList[mini] = B

print(sum(ansList))

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.append(a)
    B.append(b)

ans = 0
for d in range(M):
    if len(A)<=0:
        break
    
    max_i = 0
    max_limit = 0
    max_reward = 0
    for i in range(len(A)):
        if A[i] <= (M - d):
            if max_reward == B[i]:
                if A[max_i] < A[i]:
                    max_i = i
                    max_reward =  B[i]
            if max_reward < B[i]:
                max_i = i
                max_reward =  B[i]
    ans += max_reward
    A.pop(max_i)
    B.pop(max_i)

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 for _ in range(m+1)]

for a, b in abab :
    for i in range(a, m+1) :
        if gyara[i] == 0 :
            gyara[i] = b
            break

print(gyara)
print(sum(gyara))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N,M = [int(s) for s in input().split()]
baito=[]
for i in range(N):
  a,b = [int(s) for s in input().split()]
  baito=baito+[[a,b]]
baito=sorted(baito, key=lambda x: -x[1]*1000000-x[0])
day=0
money=0
#間に合うものの中で一番高いバイトをする
#高いバイトから順に見る
i=0
while(i<N and day<M):
  #間に合わないなら削除
  if(baito==[]):
    break
  if(baito[0][0]>M-day):
    i=i+1
  #間に合うなら受ける
  else:
    money=money+baito[0][1]
    del baito[0]
    day=day+1
    i=i+1
print(money)

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
for i in range(int(m)):
    if j>=n:break
    if m>=int(ab_s[j][0]) and j==0:
        ct+=int(ab_s[j][1])
        #print(ct,ab_s[j],0)
        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)
        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<=m:
            ct+=int(ab_s[j][1])
            #print(ct,ab_s[j],2)
            j+=1
        else:j+=1
    else:break
print(ct)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]
jobs.sort(key=itemgetter(0), reverse=True)
jobs.sort(key=itemgetter(1), reverse=True)

ans = 0
for i in range(n):
    if m < jobs[i][0]:
        continue
    else:
        ans += jobs[i][1]
        m -= 1
print(ans)

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**5)]
for i in range(N):
    [An,Bn] = list(map(int,input().split()))
    d[Bn-1].append(An)
for i in range(10**5):
    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 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])
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 = (int(x) for x in input().split())
arr = [tuple(map(int, input().split())) for _ in range(n)]
arr = sorted(arr, key=lambda x: (-x[1],-x[0]))
ans = 0
i = 0
while(i < n):
  if(i + arr[i][0] <= m):
    ans += arr[i][1]
  i += 1
  
print(ans)

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
    if k >= 0:
        l = bisect.bisect_right(a_list_2[:k + 1], max(a_list_2[:k + 1])) - 1
        if a_list_1[l] <= m - i:
            ans += a_list_2[l]
            del a_list_1[l], a_list_2[l]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def cmp(x, y):
    if x[1] != y[1]:
        return x[1] - y[1]
    return y[0] - x[0]

N, M = map(int, raw_input().split())
l = list()

for i in range(N):
    a, b = map(int, raw_input().split())
    l.append((a,b))

l.sort(cmp=cmp, reverse=True)
#print l
sum = 0
for i in range(1, M+1):
    #print i, l
    for j in l:
        if j[0] > i:
            continue
        else:
            sum += j[1]
            l.remove(j)

print sum

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)
min_day = min([x[0] for x in AB])

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

print(reward)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

while P:
    p = P.popleft()
    if p[0] <= M:
        ans += p[1]
        M -= 1
    if M == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC 137, d
from operator import itemgetter

n, m = [int(el) for el in input().split(' ')]
X = []
for i in range(n):
    a, b =  [int(el) for el in input().split(' ')]
    X.append((a, b))

total = 0
for i in range(m):
    X = [x for x in X if x[0] + i <= m]
    if X:
        x = max(X, key = itemgetter(1, 0))
        total += x[1]
        X.remove(x)
    else:
        break

print(total)

Submission status: Wrong Answer

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

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

AB_list = sorted(AB_list)

schedule = [0]*(M+1)
day = 0
hold_joblist = [0]

#どう考えてもTLE
for i in range(N):
    if day < AB_list[i][0]:
        day = AB_list[i][0]
        if M < day:
            break
    if schedule[day] == 0:
        if hold_joblist[0] < AB_list[i][1]:
            schedule[day] = AB_list[i][1]
        else:
            schedule[day] = hold_joblist.pop(0)
            if hold_joblist[0] < AB_list[i][1]:
                hold_joblist.insert(0,AB_list[i][1])
            else:
                hold_joblist.append(AB_list[i][1])
                list.sort(hold_joblist, reverse=True)
    elif schedule[day] < AB_list[i][1]:
        if hold_joblist[0] < schedule[day]:
            hold_joblist.insert(0,schedule[day])
        else:
            hold_joblist.append(schedule[day])
            list.sort(hold_joblist, reverse=True)
        schedule[day] = AB_list[i][1]
    else:
        if hold_joblist[0] < AB_list[i][1]:
                hold_joblist.insert(0,AB_list[i][1])
        else:
            hold_joblist.append(AB_list[i][1])
            list.sort(hold_joblist, reverse=True)

for i in range(day+1,M+1):
    if hold_joblist:
        schedule[i] = hold_joblist.pop(0)
    else:
        break

print(sum(schedule))

Submission status: Wrong Answer

Solution code:
from array import array
from collections import deque

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

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

day = 0
payment = 0

for a,b in AB:
    payment_day = day + a
    if payment_day <= M:
        #print('-',a,b)
        payment += b
        day += 1

#print(AB)
print(payment)

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
for i in range(int(m)):
    if j>=n:break
    if m>=int(ab_s[j][0]) and j==0:
        ct+=int(ab_s[j][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])
        j+=1
    elif 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<=m:
            ct+=int(ab_s[j][1])
            j+=1
        else:j+=1
    else:break
print(ct)

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]))

ans = 0
c = 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 == M:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

add,ans = 0,0
for a,b in ab:
    if a+add <= M:
        ans += b
        add += 1
print(ans)

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)]

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
A = [0] * N
B = [0] * N
res = 0
tmp_max = 0
tmp_index = -1
for i in range(N):
    A[i], B[i] = map(int, input().split())
A = np.array(A)
B = np.array(B)
for j in range(1,M+1):
    if len(B[A <= j]) != 0:
        tmp_max = max(B[A <= j])
        res = res + tmp_max
        tmp_index = np.where(B == tmp_max)[0][0]
        A = np.delete(A, tmp_index)
        B = np.delete(B, tmp_index)
print(res)

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
    if k >= 0:
        l = k
        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]
print(ans)

Submission status: Wrong Answer

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

ass_s = sorted(ass,key=lambda x:x[1])[::-1]
sur = 0
for i in range(N):
    day,pay = ass_s[i]
    if M-day >= 0 :
        sur += pay
        M -= 1
    elif M <= 0:
        break
    else:
        continue
print(sur)

Submission status: Wrong Answer

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

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

v=[]
for i in range(1,m+1):
    v.append(i)

for i in range(min(m,n)):
    if len(v)==0:
        break
    if x[i][0]<=v[-1]:
        ans+=x[i][1]
        for j in range(m):
            if v[j]>=x[i][0]:
                del v[j]
                break
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
ba = [None] * n
for i in range(n):
    a, b = map(int, input().split())
    ba[i] = [b, a]
ba.sort(reverse=True)
li = [[i] for i in range(m)]
ans = 0
for i in range(n):
    b, a = ba[i]
    if m - a < 0 or li[m - a][0] == -1:
        continue
    if m - a > 0:
        li[m - a] = li[m - a - 1] if li[m - a - 1][0] <= li[m - a][0] - 1 else [li[m - a][0] - 1]
        if li[m - a][0] > -1:
            ans += b
    else:
        li[m - a] = [-1]
        ans += b
print(ans)

Submission status: Wrong Answer

Solution code:
class work(object):
    def __init__(self, nums):
        self.a = nums[0]
        self.b = nums[1]
        self.is_used = False

    def __repr__(self):
        return "({}, {})".format(self.a, self.b)

    def __lt__(self, other):
        if self.a == other.a:
            return self.b > other.b
        return self.a < other.a


(n, m) = map(int, input().split())
works = []
for _ in range(n):
    works.append(work(list(map(int, input().split()))))
sorted_works = sorted(works)

sum = 0
for i in range(1, m + 1):
    index = 0
    for j, w in enumerate(sorted_works):
        if i < w.a:
            break
        index += 1
    if 0 == index:
        continue
    partial_sorted = sorted(
        sorted_works[:index], key=lambda x: x.b, reverse=True)
    max_index = 0
    max_reward = 0
    for j, work in enumerate(partial_sorted):
        if not work.is_used:
            max_index = j
            max_reward = work.b
            break
    sum += max_reward
    sorted_works[max_index].is_used = True

print(sum)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, M = MAP()
    A = MATINT(N)
    A.sort()
    sumv = 0
    mm = 1
    # A += [[10**6, 10**6]]
    aa = 0
    count = 0
    tmp = []
    while aa < N:
        if A[aa][0] <= mm:
            tmp.append(A[aa][1])
            aa += 1
        else:
            # print(aa, mm, count, tmp)
            if tmp:
                maxv = max(tmp)
                count += maxv
                tmp.remove(maxv)
            mm += 1
    while mm <= M:
        # print(aa, mm, count, tmp)
        if tmp:
            maxv = max(tmp)
            count += maxv
            tmp.remove(maxv)
        mm += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ar = []
for i in range(n):
    aa, bb = map(int, input().split())
    ar.append((bb, aa))
ar = sorted(ar, reverse=True)

ans = 0
i = 0
for d in reversed(range(m + 1)):
    while i < len(ar) and ar[i][1] > d:
        i += 1
    if i == len(ar):
        break

    ans += ar[i][0]
    i += 1
    if i >= len(ar):
        break
print(ans)

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)

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:
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])

daysetl = list(dayset)
daysetl = sorted(daysetl, reverse=True)
ans = 0
for i in range(1,m+1):
    """print("i",i)
    print("ans",ans)
    print(dayset)
    print(d)"""
    if len(daysetl)==0:
      continue
    daysettmp = daysetl
    targetd = daysettmp[-1]
    targetdset = set()
    targetdset.add(targetd) 
    daysettmp= daysettmp[:-1]
    
    if targetd > i:
        continue
    else:
        while((targetd < i)&len(daysettmp) > 0):
                targetd = daysettmp[-1]
                targetdset.add(targetd)
                daysettmp = daysettmp[:-1]
        
    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:
            daysetl.remove(maxp_d)
        else:
            d[maxp_d] = d[maxp_d][:-1]

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  if A > M:
    continue
  else:
    AB.append([A, B])

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

today = 0
total_benefit = 0

for ab in AB:
  days, benefit = ab[0], ab[1]
  if today + days > M: #期限内に終わらない場合
    continue
  else:
    total_benefit += benefit
    today += 1

print(total_benefit)

Submission status: Wrong Answer

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

A.sort(reverse=True)
day=1
result=0
for i in range(N):
    if day+A[i][1]<=M+1:
        result+=A[i][0]
        day+=1
    if day==M+1:
        break
print(result)

Submission status: Wrong Answer

Solution code:
from pprint import pprint
N,M = map(int,input().split())
bl = []

for _ in range(N):
    days,money = map(int,input().split())
    bl.append([days,money])

bl = sorted(bl,key=lambda x:(-x[1],x[0]))
spenddays = 0
dl = []
ans = 0
for b in bl:
    cond_spenddays = max(spenddays,b[0]+(dl+[b[0]]).count(b[0])-1)
    if(cond_spenddays<=M):
        dl.append(b[0])
        ans += b[1]
        spenddays = max(spenddays,b[0]+dl.count(b[0])-1)
        if(len(dl)>=M):
            break

print(ans)

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[0], reverse=True)
li.sort(key=lambda x: x[1], reverse=True)
for i in li:
    if i[0] <= M:
        ans += i[1]
        M -= 1
li.sort(key=lambda x: x[0], 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 = map(int, input().split())
arr = [list(map(int,input().split())) for _ in range(n)]
arr1 = sorted(arr, key=lambda x: (x[1],x[0]), reverse=True)
sums = 0
j = 0
for i in range(n):
  a = arr1[i][0]
  if i+a <= m:
    sums +=arr1[i][1]
  else:
    continue
print(sums)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
# AB_s = [list(map(int,input().split())) for _ in range(N)]
dicts = {i:[] for i in range(1,M+1)}
for _ in range(N):
    A,B = map(int,input().split())
    if A in dicts:
        dicts[A].append(B)
answer = 0
wages = []
for i in range(1,M+1):
    wages.extend(dicts[i])
    if wages:
        wages.sort()
        if len(wages) > M-i:
            wages[:M-i-1] = []
        answer += wages.pop()
print(answer)
# AB_s = sorted(AB_s, key=lambda x:-x[0])
# print(AB_s)

Submission status: Wrong Answer

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

AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted([ab for ab in AB if ab[0]<=M], key=lambda a: (-a[1], -a[0]))

c=0
for remainDay in range(M,0,-1):
  for j in range(len(AB)):
    if AB[j][0] <= remainDay:
      c+=AB.pop(j)[1]
      break
print(c)

Submission status: Wrong Answer

Solution code:
# import bisect
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)
# print(d)

m = 10**10
works = []
for k, v in d.items():
    d[k] = sorted(d[k], reverse=True)
    if M-k+1 >= 1:
        for w in d[k][:M-k+1]:
            if len(works) <= M-k:
                works.append(w)
                m = min(m, w)
                # works = sorted(works, reverse=True)
            else:
                if m <= w:
                    works.append(w)
                    m = min(m, w)
            # print(M, k, d[k][:M-k+1])
# print(works)

works = sorted(works, reverse=True)
# print(works)

print(sum(works[:M]))

Submission status: Wrong Answer

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

tasks=[]
t_append=tasks.append
for i in range(n):
  a,b = map(int, input().split())
  t_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)
      #print(tasks)
      break
  if i==n-1:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

cnt = 0
A = []

for i in range(N) :
    if i >= 1 and L[i][0] != L[i-1][0] :
        cnt = 0
    
    if M-L[i][0]+1 > cnt :
        if i < M :
            heapq.heappush(A, L[i][1])
            cnt += 1
            
        else :
            minv = heapq.heappop(A)
            if minv >= L[i][1] :
                heapq.heappush(A, minv)
            else :
                heapq.heappush(A, L[i][1])
                cnt += 1

if len(A) == 0 :
    print(0)
else :    
    print(sum(A))

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[1],reverse=True)
day=list(range(1,m+1))
money=0
cnt=0
for s in ab:
  if day==[] or cnt>=m:
    break
  if s[0]<=max(day):
    money+=s[1]
    cnt+=1
    if s[0] in day:
      day.remove(s[0])
print(money)

Submission status: Wrong Answer

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

    for _ in range(n):
        s = list(map(int, input().split()))
        a.append(s[0])
        b.append(s[1])

    lv = [a[i] * b[i] for i in range(len(a))]
    li = sorted(zip(lv, a, b), reverse=True)

    for i in range(m):
        for _ in range(len(li)):
            lab = li.pop(0)
            if lab[1] <= m - i:
                ans += lab[2]
                break

    print(ans)


if __name__ == '__main__':
    p_d()

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 = []
    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
            Q2.append((b, score))
    Q2.sort()

    count = 0
    res = 0
    for b, score in Q2:
        if count >= M:
            break
        if count >= score:
            continue
        res -= b
        count += 1
    print(res)
    return


# 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())
t=[]
for _ in range(n):
    a, b = map(int, input().split())
    t.append((a,b))
    
t=sorted(t,key=lambda x: x[1],reverse=True)
for i in range(1,n):
    for j in range(i):
      if t[j][0]<t[i][0] and t[i][1]==t[j][1]:
        tmp=t[i]
        t[i]=t[j]
        t[j]=tmp
limit=m
score=0

for _ in range(n):
  if len(t)>1:
    if t[0][0]<=limit:
        score+=t[0][1]
        del t[0]
        limit-=1
    else:
        del t[0]
  else:
    break
    
print(score)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())  # N件のアルバイト, M日後までの報酬
hoge = 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(len(arubaito)):
    # 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())

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)
an.sort( key = lambda v: (v[1]*-1, v[0]*-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:
N, M = map(int, input().split())

lst = [list(map(int, input().split())) for s in range(N)]
lst = sorted(lst, key=lambda x: (-x[1], -x[0]))

r = 0

for m in range(M + 1):
    for i, c in enumerate(lst):
        if c[0] + m > M:
            del lst[i]
            continue
        else:
            r += c[1]
            del lst[i]
            break

    if len(lst) == 0:
        break


print(r)