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())
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
    while True:
        try:
            if lis[i][1] <= j:
                tot += lis[i][0]
                del lis[i]
                break
            i += 1
        except IndexError:
            break

print(tot)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
import numpy as np
ab = np.array(ab)
# print(ab)
ab = ab[np.argsort(ab[:,0])]
# print(ab)
ab= ab[np.argsort(ab[:,1])[::-1]]
# print(ab)
# print("OK")
count = 0
i = 0
while i <= m:
    c = ab[0,:]
    # print("c={}".format(c))
    # print("c0={}".format(c[0]))
    # print("c0={}".format(c[1]))
    if c[0] <= (m-i):
        count += c[1]
        ab = np.delete(ab,0,0)
        i += 1
    else:
        ab = np.delete(ab,0,0)
    # print(ab)
    if np.size(ab)==0:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
import time
import heapq


# N: バイトの種類
# M: 日数の最大
N,M = map(int,input().split(" "))

# A 日数
# b バイト代
A = []
B = []
for _ in range(N):
    a,b = map(int,input().split(" "))
    A.append(a)
    B.append(-b)

# 日数でソート
ind_sorted = sorted(range(N), key = lambda x:A[x])
tmp_a = 0
tmp_b_ls = [0]
money = 0
tmp_ind = 0
for i in range(N):
    if A[ind_sorted[i]] > M:
        break
    if tmp_a != A[ind_sorted[i]]:
        # 空いている日数
        # print(d)
        # print(tmp_b_ls)
        d = A[ind_sorted[i]]-tmp_a
        for _ in range(d):
            if tmp_b_ls == []:
                break
            money -= heapq.heappop(tmp_b_ls)
        tmp_a = A[ind_sorted[i]]
    tmp_b_ls.append(B[ind_sorted[i]])

d = M+1-tmp_a
for _ in range(d):
    if tmp_b_ls == []:
        break
    money -= heapq.heappop(tmp_b_ls)


print(money)

Submission status: Wrong Answer

Solution code:
from heapq import *

n,m=map(int,input().split())
h=[[] for _ in range(10**5+1)]
result=0

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

for i in range(1,m+1):
  max_=0
  index=0
  for j in range(1,i+1):
    if len(h[j])!=0 and max_<=h[j][-1]:
      max_=h[j][-1]
      index=j
  if index!=0:
    h[index].pop(-1)
  result+=max_
print(result)

Submission status: Wrong Answer

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

for i in range(m,0,-1):
  while(li!=[] and li[0][0]>i):
    li.pop(0)
  if len(li)==0:
    break
  max_=0
  index=-1
  for j in range(len(li)):
    if max_<li[j][1]:
      max_=li[j][1]
      index=j
  if max_!=0:
    result+=max_
    li.pop(index)
print(result)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda job: (job[0]/1000000)+job[1], reverse=True)

# print('{}'.format(new_jobs))

for job in new_jobs:
#    print('day {} max {}, checking job{}'.format(day, m, job))
    if day + job[0] <= m:
        reward = reward + job[1]
        day = day + 1
#        print('add to schedule')

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda job: (job[0]/1000000)+job[1], reverse=True)

# print('{}'.format(new_jobs))

for job in new_jobs:
    print('day {} max {}, checking job{}'.format(day, m, job))
    if day + job[0] <= m:
        reward = reward + job[1]
        day = day + 1

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda job: (job[0]/1000000)+job[1], reverse=True)

# print('{}'.format(new_jobs))

for job in new_jobs:
#    print('day {} max {}, checking job{}'.format(day, m + 1, job))
    if day + job[0] <= m:
        reward = reward + job[1]
    day = day + 1

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda job: job[0]/1000000+job[1], reverse=True)

# print('{}'.format(new_jobs))

for job in new_jobs:
#    print('day {} max {}, checking job{}'.format(day, m + 1, job))
    if day + job[0] <= m:
        reward = reward + job[1]
    day = day + 1

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda job: job[0]/100000+job[1], reverse=True)

# print('{}'.format(new_jobs))

for job in new_jobs:
#    print('day {} max {}, checking job{}'.format(day, m + 1, job))
    if day + job[0] <= m:
        reward = reward + job[1]
    day = day + 1

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda job: job[0]+job[1])

# print('{}'.format(new_jobs))

for job in new_jobs:
#    print('day {} max {}, checking job{}'.format(day, m + 1, job))
    if day + job[0] <= m + 1:
        reward = reward + job[1]
    day = day + 1

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(q)
heapq.heapify(s)
for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            #最小値をヒープから取り出す
            p=heapq.heappop(q)
            ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
for k in range(m,-1,-1):
    while True:
        if s!=[]:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            #最小値をヒープから取り出す
            p=heapq.heappop(q)
            ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            #最小値をヒープから取り出す
            p=heapq.heappop(q)
            ans+=-p
print(ans)

Submission status: Wrong Answer

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

for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            #最小値をヒープから取り出す
            p=heapq.heappop(q)
            ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
heapq.heapify(q)
for k in range(m,-1,-1):
    if s!=[]:
        #最小値を返す
        p=heapq.heappop(s)
        if p[0]+k<=m:
            #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
heapq.heapify(q)
for k in range(m-1,-1,-1):
    if s!=[]:
        #最小値を返す
        p=heapq.heappop(s)
        if p[0]+k<=m:
            #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
heapq.heapify(q)
for k in range(m-2,-1,-1):
    if s!=[]:
        #最小値を返す
        p=heapq.heappop(s)
        if p[0]+k<=m:
            #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
for k in range(m-2,-1,-1):
    if s!=[]:
        #最小値を返す
        p=heapq.heappop(s)
        if p[0]+k<=m:
            #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans+=-p
print(ans)

Submission status: Wrong Answer

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): #最小公倍数
  return a * b // gcd (a, b)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#input stock
"""
n = int(input())

#list
a = map(int, input().split())
a,b = map(int, input().split())

d=[]
for i in range(n):
  d[i]=int(input())

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""

#######################################
n,m = map(int, input().split())
a = np.zeros(n)
b = np.zeros(n)

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

money = 0
for i in range(m):
  try:
    idx = np.array(a<=(i+1))
    best_idx = np.argmax(b[idx])
    money += b[best_idx]
    b[best_idx] = 0
  except:
    pass

print(int(money))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
day = 0
reward = 0
jobs = []

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

new_jobs = sorted(jobs, key=lambda t: t[1]/t[0], reverse=True)

for job in new_jobs:
    if day + job[0] <= m:
        reward = reward + job[1]
    day = day + 1

print('{}'.format(reward))

Submission status: Wrong Answer

Solution code:
x = input()

N = int(x.split()[0])
M = int(x.split()[1])

data = []
result = 0

for counter in range(N):
    x = input()
    data.append([int(x.split()[0]),int(x.split()[1])])

for t in range(1,M+1,1):
    sarrary = []
    for work in data:
        if work[0] == t:
            sarrary.append(work[1])
    
    if sarrary == []:
        continue
    else:
        result += max(sarrary)
        
print(result)

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)
#print(work)
day = 0
money = 0
for i in range(N):
  if work[i][0] + day <= M:
    money += work[i][1]
    day += 1
print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
if __name__ == "__main__":
    M = list(map(int,input().split()))
    N = M[0]
    M = M[1]
    ABsort = np.zeros((N,2))
    for i in range(N):
        AB = list(map(int,input().split()))
        ABsort[i,0] = AB[0]
        ABsort[i,1] = AB[1]
    ABsort = ABsort[ABsort[:,-1].argsort()]
    totalbonus = 0
    jobday = 0
    for i in range(N):
        if ABsort[N-i-1,0]+jobday <= M:
            totalbonus += ABsort[N-i-1,1]
            jobday += 1        
        if jobday >= M:
            break
    print(int(totalbonus))

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])
work = work[: : -1]
#print(work)
day = 0
money = 0
for i in range(N):
  if work[i][0] + day <= M:
    money += work[i][1]
    day += 1
print(money)

Submission status: Wrong Answer

Solution code:
#おら間違えてんぞはよ直せや

import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n,m = ips()
a = []
maxdays = -1
for i in range(n):
    a.append(iprow())
    maxdays = max(maxdays,a[i][0])
before= [[] for i in range(maxdays+1)]
for i in range(n):
    targetday = a[i][0]
    salary = a[i][1]
    before[targetday].append(salary)
#print(before)
leftover = []
for i in range(len(before)):
    b = sorted(before[i])
    leftover.append(b)
#print(leftover)
days = m
total = 0
currentdays = maxdays
while days:
    #print(leftover,currentdays)
    if currentdays > days:
        currentdays = days
    if len(leftover[currentdays])==0:
        while len(leftover[currentdays])==0:
            currentdays-=1
            if currentdays==0:
                print(total)
                exit(0)
    total+=leftover[currentdays].pop(-1)
    #print(total)
    days-=1
print(total)

Submission status: Wrong Answer

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

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

reward = 0
day = M
i = 0
while (day > 0) & (i < N):
    if job[i][0] <= day:
        reward += job[i][1]
        day -= 1
    i += 1
print(reward)

Submission status: Wrong Answer

Solution code:
import heapq

N, M = [int(_) for _ in input().split(' ')]
ABs = [[] for _ in range(M + 1)]
r = 0

for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A <= M:
        ABs[A].append(-B)

for m in range(M + 1):
    ABs[m].sort()

for m in range(M, 0, -1):
    B_max = -1
    A_max = -1

    for a in range(m, 0, -1):
        if len(ABs[a]) == 0:
            continue

        b = - ABs[a][0]
        if B_max < b:
            A_max = a
            B_max = b

    if A_max != -1:
        r -= ABs[A_max].pop(0)

print(r)

Submission status: Wrong Answer

Solution code:
import heapq

N, M = [int(_) for _ in input().split(' ')]
ABs = [[] for _ in range(M + 1)]
r = 0

for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A <= M:
        ABs[A].append(-B)

for i in range(M + 1):
    heapq.heapify(ABs[i])

for m in range(M, 0, -1):
    B_max = -1
    A_max = -1

    for a in range(m, 0, -1):
        if len(ABs[a]) == 0:
            continue

        b = - ABs[a][0]
        if B_max < b:
            A_max = a
            B_max = b

    if A_max != -1:
        r -= heapq.heappop(ABs[A_max])

print(r)

Submission status: Wrong Answer

Solution code:
import heapq

N, M = [int(_) for _ in input().split(' ')]
ABs = [[] for _ in range(M + 1)]
r = 0

for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A <= M:
        ABs[A].append(-B)

for i in range(M + 1):
    heapq.heapify(ABs[i])
    print("%d: %s" % (i, str(ABs[i])))

for m in range(M, 0, -1):
    B_max = -1
    A_max = -1

    for a in range(m, 0, -1):
        if len(ABs[a]) == 0:
            continue

        b = - ABs[a][0]
        if B_max < b:
            A_max = a
            B_max = b

    if A_max != -1:
        r -= heapq.heappop(ABs[A_max])

print(r)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
lst = [[int(i) for i in input().split()] for i in range(n)]
lst.sort(key=lambda x:(x[1], x[0]), reverse=True)
ans = 0
for i in reversed(range(m)):
    for j in range(len(lst)):
        if lst[j][0] <= i+1:
            l = lst.pop(j)
            ans += l[1]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

tasks = []
heapq.heapify(tasks)
for n in range(N):
	A,B = map(int,input().split())
	heapq.heappush(tasks,(-B,-A))
#print(tasks)

ans = 0
while 0<M and tasks:
	#print(tasks)
	item = heapq.heappop(tasks)
	gain = -item[0]
	days = -item[1]
	if M<days:
		continue
	#print('\t{:02d}: day={}: {}'.format(M,days,item))
	ans += gain
	M -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
#おら間違えてんぞはよ直せや

import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n,m = ips()
a = []
maxdays = -1
for i in range(n):
    a.append(iprow())
    maxdays = max(maxdays,a[i][0])
before= [[] for i in range(maxdays+1)]
for i in range(n):
    targetday = a[i][0]
    salary = a[i][1]
    before[targetday].append(salary)
print(before)
leftover = []
for i in range(len(before)):
    b = sorted(before[i])
    leftover.append(b)
print(leftover)
days = m
total = 0
currentdays = maxdays
while days:
    print(leftover,currentdays)
    if currentdays > days:
        currentdays = days
    if len(leftover[currentdays])==0:
        while len(leftover[currentdays])==0:
            currentdays-=1
            if currentdays==0:
                print(total)
                exit(0)
    total+=leftover[currentdays].pop(-1)
    print(total)
    days-=1
print(total)

Submission status: Wrong Answer

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

AB_list = [list(map(int,input().split())) for i in range(N)]
check = [0]*N
B = 0
flag = 0
payment = 0
for i in range(1, M+1):
    for j in range(0, N):
        if (AB_list[j][0] <= i) and (check[j] == 0) and (AB_list[j][1] > B):
            B = AB_list[j][1]
            c = j
            flag = 1
        
        print(check[j] == 0)
    payment = payment + B
    if flag == 1:
        check[c] = 1
    print(B)
    B = 0

print(payment)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy as np

N, M = [int(a) for a in input().split()]

jobs = [[] for _ in range(M)]
print(jobs)

for _ in range(N):
    a, b = map(lambda x: int(x), input().split())
    print(a, b, M-a)
    if a > M:
      continue
    jobs[M-a].append(b)

heap = []
ans = 0
for i in range(M-1, -1, -1):
    for b in jobs[i]:
        # 降順にするためにマイナスをつけて入れる
        heapq.heappush(heap, -b)
    if len(heap) != 0:
        # 取り出した値にマイナスをつけて元に戻す
        ans += -heapq.heappop(heap)
print(ans)

Submission status: Wrong Answer

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

from operator import neg
from bisect import bisect_left


MIN = -10**5-1


def solve(N, M, A, B):
    ab = list(sorted(zip(A, map(neg, B))))
    print(ab)
    total = 0
    for i in range(1, M+1):
        right = bisect_left(ab, (i, MIN))
        if right >= len(ab):
            right -= 1
        if ab[right][0] > i:
            right -= 1

        pos = -1
        bmax = -1
        for j in range(right, -1, -1):
            if -ab[j][1] > bmax:
                bmax = -ab[j][1]
                pos = j
        if pos >= 0:
            ab = ab[0:pos] + ab[pos+1:]
            total += bmax
    return total


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for idx in range(N):
        A[idx], B[idx] = map(int, input().split())

    ans = solve(N, M, A, B)

    print(ans)

Submission status: Wrong Answer

Solution code:
#coding utf-8
import heapq
N,M=map(int,input().split())
AB= [[int(i) for i in input().split()] for i in range(N)]
AB.sort(reverse=True)
work=[]
heapq.heapify(work)
ans=0
for i in range(1,M+1):
  while AB and AB[-1][0] <=i:
      tmp=AB.pop()
      heapq.heappush(work,-tmp[1])
  if work:
    tmp=heapq.heappop(work)
    ans-=tmp

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[[] for i in range(m)]
s=[]
for i in range(n):
   a,b=map(int,input().split())
   if a<=m:
     l[a-1].append(b)
for i in range(m):
   l[i].sort(reverse=True)
for i in range(m):
   for j in range(min(m-i,len(l[i]))):
      s.append(l[i][j])
s.sort(reverse=True)

t = 0
for i in range(min(m, len(s))):
  t += s[i]
print(t)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
baito = [list(map(int, input().split())) for i in range(n)]
sorted_baito = sorted(baito, key=lambda x:(-x[1], -x[0]))
d = 0
ans = 0

for i in range(len(sorted_baito)):
    if d + sorted_baito[0][0] <= m:
        ans += sorted_baito[0][1]
        d += 1
    sorted_baito.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
albeit = {i: list(map(int, input().split())) for i in range(N)}

z = 1 #z日前
#M-z日目にどの仕事を請けるか
sum_r = 0
albeit_ = {}
albeit__ = {}
r = []
r_ = []
while M - z >= 0:
  if len(albeit) > 0:
    r.extend([a for a, b in albeit.items() if b[0] == z])
    for c in r:
      albeit_[c] = albeit[c]
      r_.append(c)
      del albeit[c]
  
  if len(albeit_) == 0:
    z += 1
    break

  ind = [d for d, e in albeit_.items() 
         if e[1] == max([albeit_[f][1] for f in r_])]
  
  for k in ind:
    albeit__[k] = albeit_[k]
  
  ind_ = [g for g, h in albeit__.items()
         if h[0] == min([albeit__[j][0] for j in ind])][0]
  
  sum_r += albeit_[ind_][1]
  
  del albeit_[ind_]
  r_.remove(ind_)
  r.clear()
  albeit__.clear()
  

  z += 1
  
print(sum_r)

Submission status: Wrong Answer

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

job = sorted(job, key = lambda x: x[0], reverse=True)
job = sorted(job, key = lambda x: x[1], reverse=True)
reward = 0
day = 0
for i in range(N):
    if (day + job[i][0]) <= M:
        reward += job[i][1]
        day += 1
    if day == M:
        break
print(reward)

Submission status: Wrong Answer

Solution code:
import heapq
def main(n,m,c):
    cost_map = dict([(i, [])for i in range(1,m+1)])
    print(cost_map)
    for a, b in c:
        if a <= m:
            cost_map[a].append(b)
        
    hp =[]
    ret = 0
    for i in range(1, m+1):
        costs = cost_map[i]
        [heapq.heappush(hp, -c) for c in costs]
        if(len(hp) > 0):
            c = heapq.heappop(hp)
            ret -= c
    return ret
if __name__ == "__main__":
    n,m = map(lambda x: int(x), input().strip().split())
    c = [ list(map(lambda x: int(x), input().strip().split())) for i in range(n)]
    print(main(n,m,c))

Submission status: Wrong Answer

Solution code:
import heapq

N, M = map(int, input().split())
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 = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        if l[j][0] <= i:
            heapq.heappush(tmp, l[j])
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[1]
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
ls = []
N, M = map(int, input().split())
for i in range(N):
  A, B = map(int, input().split())
  if A<=M:
    heappush(ls, (A,-B))
ans = 0
for i in range(1,M+1):
  if ls==[]:
    break
  y = heappop(ls)
  A, B = y
  m = -y[1]
  stuck = []
  if A>i:
    heappush(ls,y)
    continue
  while A<=i and ls:
    x = heappop(ls)
    A, B = x
    if y[1]>x[1]:
      m = -x[1]
      stuck += [y]
      y = x
    else:
      stuck += [x]
  for s in stuck:
    heappush(ls,s)
  ans += m
  
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
cond = []
for i in range(n):
  a,b = map(int, input().split())
  cond.append([a,b])
cond.sort()
a = [cond[i][0] for i in range(n)]
b = [cond[i][1] for i in range(n)]
money = 0

a_new = a
for t in reversed(range(0,m+1)): 
  for i in reversed(range(len(a))):
    if a[i]>m-t:
      a_new.remove(a[i])
    else:
      break
  #その中の最大値を足す
  new_b = b[:len(a_new)]
  if len(new_b)>0:
    b_max = max(new_b)
    b_max_idx = new_b.index(b_max)
    money += max(new_b)
    a.remove(a[b_max_idx])
    b.remove(b[b_max_idx])  
  
print(money)

Submission status: Wrong Answer

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

inc = 0
ab = []

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

ab.sort(reverse=True)

for i in range(1, M+1):
    count=0
    for j in ab:
        if j[1] <= i:
            inc += j[0]
            ab[count] = [0, 100]
            break
        count+=1
print(inc)

Submission status: Wrong Answer

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

inc = 0
ab = []

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

ab.sort(reverse=True)

for i in range(0, M):
    count=0
    for j in ab:
        if j[1] <= i:
            inc += j[0]
            ab[count] = [0, 100]
            break
        count+=1
print(inc)

Submission status: Wrong Answer

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

def sol():
    n,m=map(int,input().split())
    d=[]
    ans=[0]*(m+1)
    t=0
    ans[0]=1
    y=m
    for i in range(n):
        a,b=map(int,input().split())
        if a<=m: heapq.heappush(d,(-b,-a))
    while len(d):
        bb,aa=heapq.heappop(d)
        aa*=-1
        if 0 not in ans:
            break
        if max(ans.index(0),aa)==y:
            ans[y]=1
            t+=bb
            y-=1
        else:
            for j in range(max(ans.index(0),aa),y+1):
                if ans[j]==0:
                    ans[j]=1
                    t+=bb
                    break

    print(-1*t)

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

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

inc = 0
ab = []

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

ab.sort(reverse=True)

for i in range(M, 0, -1):
    count=0
    for j in ab:
        if j[1] <= i:
            inc += j[0]
            ab[count] = [0, 100]
            break
        count+=1
print(inc)

Submission status: Wrong Answer

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

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

ans = 0
now = 0
for i in range(N):
    if now + a[i][0] <= M:
        ans += a[i][1]
        now += 1

print(ans)