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:
import numpy as np
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)

sort = np.argsort(A)
A = list(np.array(A)[sort])
B = list(np.array(B)[sort])
#print (A)
#print (B)

day = 0
total = 0
for j in range (N+1):
    #print ("day",day)
    #print ("B",B)
    lst = []
    for i in range (len(A)):
        if A[i] <= M - day:
            lst.append(B[i])
        else:
            break
    #print ("lst",lst)
    if len(lst) == 0:
        day += 1
    else:
        sort = np.argsort(lst)
        lst = list(np.array(lst)[sort])
        total += lst[-1]
        B[sort[-1]] = 0
        day += 1
    
        
print (total)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

N, M = map(int, input().split())
dLst = [list(map(int, input().split())) for i in range(N)]
tmpL = sorted(dLst, key=lambda x: (x[1], x[0]), reverse=True)
totalLst = []
index = 0
for i in range(N):
    for j in range(index, len(tmpL)):
        if tmpL[j][0] <= M - i:
            totalLst.append(tmpL[j][1])
            index = j + 1
            break

print(sum(totalLst))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

rewords = {}
maxes = np.zeros(M)

for i in range(N):
  A, B = list(map(int, input().split()))
  if A > M:
    continue
    
  if A in rewords.keys():
    rewords[A].append(B)
    maxes[-A] = np.max(rewords[A])
  
  else:
    rewords[A] = [0, B]
    maxes[-A] = B

R = 0
rest = M
for i in range(M):
  idx = np.argmax(maxes[-rest:]) + (M - rest)
  r = maxes[idx]
  if not (r == 0):
    R += r
    rewords[M - idx].remove(r)
    maxes[idx] = np.max(rewords[M - idx])
  
  rest -= 1

print(int(R))

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

ans = 0
day = 0
for a, b in AB:
  if a + day > M:
    break
  ans += b
  day += 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())
    if a<=m:
        L.append([a,b])
L = sorted(L,key=lambda x:x[0])
L = sorted(L,key=lambda x:x[1])
rew = 0
ld = m

for i in range(m):
    if len(L)== 0:
        break
    Lt = [j for j in L if j[0]==ld]
    if len(Lt)!=0:
        rew += Lt[-1][1]
    else:
        rew += L[-1][1]
        L.pop(-1)
    L = [j for j in L if j[0]<ld]
    ld -= 1
    
print(rew)

Submission status: Wrong Answer

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

for k1 in range(N):
    a, b = map (int, input().split())
    list.append([a,b])
#print(list)
list.sort(key=lambda x: x[0], reverse = True)
#print(list)
list.sort(key=lambda x: x[1], reverse = True)
#print(list)

earn = 0
day = 0
for k, v in enumerate(list):
    if v[0] <= M:
        earn += v[1]
        day += 1
#        print(M)
        M -= 1
#        print(v)

print(earn)

Submission status: Wrong Answer

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

for k1 in range(N):
    a, b = map (int, input().split())
    list.append([a,b])
list.sort(key=lambda x: x[0], reverse = True)
list.sort(key=lambda x: x[1], reverse = True)

earn = 0
day = 0
for k, v in enumerate(list):
    if v[0] <= M:
        earn += v[1]
        day += 1
        M -= 1

print(earn)

Submission status: Wrong Answer

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

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

rem = m
gain = 0

for que in range(n):
    if lst[que][0] <= rem:
        gain += lst[que][1]
        rem -= 1
    if rem == 0:
      break

print(gain)

Submission status: Wrong Answer

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

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

rem = m
gain = 0

for que in range(n):
    if lst[que][0] <= rem:
        gain += lst[que][1]
        rem -= 1

print(gain)

Submission status: Wrong Answer

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

l = []
a = [0] * m

for i in range(n):
    array = list(map(int, input().split()))
    l.append(array)

l = sorted(l, key=lambda x: (x[1],x[0]), reverse=True)
# print(l)

for i in range(len(l)):
    if l[i][0] + i <= m:
        a[i] = l[i][1]

print(sum(a))

Submission status: Wrong Answer

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

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

arr.sort(reverse=True)

res = 0
a_i = 0
m_i = m
while m_i >= 1 and a_i < len(arr):
    b, a = arr[a_i]
    if a <= m_i:
        res += b
        m_i -= 1
    a_i += 1


print(res)

Submission status: Wrong Answer

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

for i in range(n):
  a, b = map(int, input().split())
  l[i][0] = a
  l[i][1] = b

l.sort(reverse=True, key=lambda x: x[1])
l.sort(reverse=True)
#print(l)

c = 0
ans = 0
for j in range(m):
  temp = 0
  if c > n-1:
    break
  while temp == 0 and c <= n-1:
    if l[c][0] <= m-j:
      temp = l[c][1]
      c += 1
    else:
      c += 1
  #print(j, temp)
  ans += temp
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  a, b = map(int, input().split())
  l[i][0] = a
  l[i][1] = b

l.sort(reverse=True)
l.sort(reverse=True, key=lambda x: x[1])
#print(l)

c = 0
ans = 0
for j in range(m):
  temp = 0
  if c > n-1:
    break
  while temp == 0 and c <= n-1:
    if l[c][0] <= m-j:
      temp = l[c][1]
      c += 1
    else:
      c += 1
  #print(j, temp)
  ans += temp
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
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline--------------------------------------------
    N,M = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    AB.sort(reverse = True)
    heap = []
    ans = 0
    for i in range(1,M+1):
        while AB and AB[-1][0]<i:
            heappush(heap,-AB.pop()[1])
        if heap:
            ans -= heappop(heap)
    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 = [int(x) for x in input().split()]

jobs = [None] * n
for i in range(n):
  a, b = [int(x) for x in input().split()]
  jobs[i] = (b, a)

jobs.sort(reverse=True)

sal = 0
d = 0
j = 0
while d < m and j < n:
  job = jobs[j]
  if d + job[1] <= m:
    sal = sal + job[0]
    d += 1
  j += 1

print(sal)

Submission status: Wrong Answer

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

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

tot = 0
for j in range(m, 0, -1):
    i = 0
    l = len(lis)
    while True:
        if i == l:
            break
        elif lis[i][1] <= j:
            tot += lis[i][0]
            del lis[i]
            l -= 1
            break
        i += 1

print(tot)