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 heapq
n,m = map(int,input().split())
AB =[tuple(map(int,input().split())) for i in range(n)]
ans,memo=0,0
hq=[]
AB.sort(key=lambda tup:tup[0])
for day in range(m):
	for i in range(memo,n):
		if AB[i][0]<=(day+1):
			heapq.heappush(hq,AB[i][1])
			memo+=1
		else:
			break
	if len(hq):	
		ans += -heapq.heappop(hq)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from heapq import heappush, heappop

# initialize
val = 0
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
day = 1
all_salary = 0

hiyatoi = tuple(map(tuple,hiyatoi))
hq = []
hq2 = []

for index in range(n):
  heappush(hq,hiyatoi[index])

while 1:
  while hq[0][0]<=day:
    temp = np.array(heappop(hq))*[1,-1]
    temp[0],temp[1] = temp[1],temp[0]
    heappush(hq2,tuple(temp))
    #heappush(hq2,tuple(np.array(heappop(hq))*[1,-1]))
    if len(hq)==0:
      break

  if len(hq2)>0:
    salary,_ = heappop(hq2)
    all_salary -= salary

  if len(hq2)>0:  
    n = len(hq2)
    for index in range(n):
      temp = np.array(heappop(hq2))*[1,-1]
      temp[0],temp[1] = temp[1],temp[0]
      heappush(hq,tuple(temp))
      #heappush(hq,tuple(np.array(heappop(hq2))*[1,-1]))

  if len(hq)==0 or day==m:
    break

  day += 1

print(all_salary)

Submission status: Wrong Answer

Solution code:
import numpy as np
from heapq import heappush, heappop

# initialize
val = 0
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
day = 1
all_salary = 0

hiyatoi = tuple(map(tuple,hiyatoi))
hq = []
hq2 = []

for index in range(n):
  heappush(hq,hiyatoi[index])

while 1:
  while hq[0][0]<=day:
    temp = np.array(heappop(hq))*[1,-1]
    temp[0],temp[1] = temp[1],temp[0]
    heappush(hq2,tuple(temp))
    #heappush(hq2,tuple(np.array(heappop(hq))*[1,-1]))
    if len(hq)==0:
      break
  print(hq2)
  if len(hq2)>0:
    salary,_ = heappop(hq2)
    all_salary -= salary

  if len(hq2)>0:  
    n = len(hq2)
    for index in range(n):
      temp = np.array(heappop(hq2))*[1,-1]
      temp[0],temp[1] = temp[1],temp[0]
      heappush(hq,tuple(temp))
      #heappush(hq,tuple(np.array(heappop(hq2))*[1,-1]))

  if len(hq)==0 or day==m:
    break

  day += 1

print(all_salary)

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, m, *ab = map(int, string.split())
    ba = sorted([(b, a) for a, b in zip(*[iter(ab)] * 2)], reverse=True)
    ans = 0
    for _b, _a in ba:
        if _a <= m:
            ans += _b
            m -= 1
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Wrong Answer

Solution code:
n,m = [int(i) for i in input().split()]

l = []
for i in range(n):
    k = [int(i) for i in input().split()]
    l.append(k)
l = sorted(l,key = lambda x :(-x[1],-x[0]))

ret = 0
for i in l:
    if m <= 0:
        break
    else:
        if i[0] <= m:
            ret += i[1]
            m -= 1 
        else:
            pass
print(ret)

Submission status: Wrong Answer

Solution code:
import heapq
n,m = map(int,input().split())
j = []
for i in range(n):
    j1 = list(map(int,input().split()))
    j.append(j1)
j.sort(key=lambda x:x[1],reverse=True)
j.sort(key=lambda x:x[0])
day = 1
i = 0
q = []
ans = 0
count = 0
while day <= m and i < n:
    if day == j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        i = i + 1
    elif day > j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        i = i + 1
        count = count + 1
    else:
        day = day + 1
while day <= m and count > 0:
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        count = count - 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import heapq
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_map = {}


def attempt(heap_taple_list,remain_date,exe_count=0,sum_salary=0):
    candidate_list = []
    finish_flag =False
    if ( exe_count + remain_date ) > N:
        attenpt_num = N - exe_count
        finish_flag = True
    else:
        attenpt_num = remain_date
    for i in range(attenpt_num):
        candidate = heapq.heappop(heap_taple_list)
        heapq.heappush(candidate_list,(candidate[1],candidate[0])) #(a,b)にする
        
    for i in range(attenpt_num):
        candidate = heapq.heappop(candidate_list) 
        if  remain_date >= candidate[0] * (-1):
            remain_date -= 1
            sum_salary += candidate[1] * (-1)
    
    if remain_date == 0 or finish_flag:
        return sum_salary
    return attempt(heap_taple_list,remain_date,exe_count=exe_count+attenpt_num,sum_salary=sum_salary)

salary_and_need_date_list = []
sample =(2,4)
 
for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    heapq.heappush(salary_and_need_date_list,(b*(-1), a*(-1)))
salary_count = attempt(salary_and_need_date_list,M)
        
print(salary_count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import heapq
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_map = {}


def attempt(heap_taple_list,remain_date,exe_count=0,sum_salary=0):
    candidate_list = []
    finish_flag =False
    if ( exe_count + remain_date ) > N:
        attenpt_num = N -exe_count
        finish_flag = True
    else:
        attenpt_num = remain_date
    for i in range(attenpt_num):
        candidate = heapq.heappop(heap_taple_list)
        heapq.heappush(candidate_list,(candidate[1],candidate[0])) #(a,b)にする
        
    for i in range(attenpt_num):
        candidate = heapq.heappop(candidate_list) 
        if  remain_date >= candidate[0] * (-1):
            remain_date -= 1
            sum_salary += candidate[1] * (-1)
    
    if remain_date == 0 or finish_flag:
        return sum_salary
    return attempt(heap_taple_list,remain_date,exe_count=exe_count+attenpt_num,sum_salary=sum_salary)

salary_and_need_date_list = []
sample =(2,4)
 
for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    heapq.heappush(salary_and_need_date_list,(b*(-1), a*(-1)))
salary_count = attempt(salary_and_need_date_list,M)
        
print(salary_count)

Submission status: Wrong Answer

Solution code:
n,m = [int(i) for i in input().split()]

l = []
for i in range(n):
    k = [int(i) for i in input().split()]
    l.append(k)
l = sorted(l,key = lambda x :(-x[1],-x[0]))

ret = 0
for i in l:
    if i[0] <= m:
        ret += i[1]
        m -= 1 
    else:
        pass
print(ret)

Submission status: Wrong Answer

Solution code:
N,M=[int(n) for n in input().split()]
a = []
for i in range(N):
  a.append([int(n) for n in input().split()])
sa = sorted(a, key=lambda x: x[1], reverse=True)
sfa = [x for x in sa if x[0]<=M][:M]
print(sum([x[1] for x in sfa]))

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, (-B,A))
ans = 0
for i in range(1,M+1):
  if ls==[]:
    break
  x = heappop(ls)
  #print(x, i)
  B, A = x
  B = -B
  if A>i:
    heappush(ls,x)
    continue
  ans += B
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
albeit = [list(map(int, input().split())) for i in range(N)]
days = [albeit[p][0] for p in range(N)]
reward = [albeit[q][1] for q in range(N)]

z = 1 #z日前
#M-z日目にどの仕事を請けるか
sum_r = 0
r_ = {}
days_ = {}
reward_ = {}

while M - z >= 0:
  r = [a for a, b in enumerate(days) if b == z]
  for c in r:
    r_[c] = c
    days_[c] = days[c]
    reward_[c] = reward[c]
      
  if len(r_) == 0:
    z += 1
    continue
  
  print('index', r_, 'days', days_, 'reward', reward_)

  days__ = {}
  ind = [s for s , t in reward_.items() if t == max(reward_.values())]
  for f in ind:
    days__[f] = days_[f]
  ind_ = [d for d , e in days__.items() if e == min(days__.values())][0]
  
  print(r_[ind_], days_[ind_], reward_[ind_], '!!!')
  sum_r += reward_[ind_]
  z += 1
  del r_[ind_]
  del days_[ind_]
  del reward_[ind_]
  days__.clear()

print(sum_r)

Submission status: Wrong Answer

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

hq = []
max_income = 0
j = 0
for i in range(1,m+1):
    while j < n and job_list[j][0] <= i:
        heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))
        j += 1
    if len(hq) < 1:
        continue
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i

print(max_income)

Submission status: Wrong Answer

Solution code:
import heapq
n,m = map(int, input().split())
job = {}
for i in range(n):
    a,b = map(int, input().split())
    if a not in job.keys():
        job[a] = [(-b,a)]
    else:
        job[a].append((-b,a))

hq = []

max_income = 0
for i in range(1,m+1):
    if i in job.keys():
        for j in job[i]:
            heapq.heappush(hq,(j))
    if len(hq) < 1:
        break
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i

print(max_income)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

cands_list = [[] for _ in range(M)]
for x in ABs:
    if x[0]-1 < M:
    	cands_list[x[0]-1].append(x[1])

print(cands_list)

reward = 0
cands = []
for i in range(M):
    cands.extend(cands_list[i])
    if len(cands) > 0:
        best = max(cands)
        reward += best
        cands.remove(best)

print(reward)

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())
        #d.append((b,a))
        heapq.heappush(d,(-b,-a))
    #d.sort(reverse=True)
    #for bb,aa in d:
    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:
import sys
input=sys.stdin.readline

def sol():
    n,m=map(int,input().split())
    d=[]
    ans=set([0])
    t=0
    y=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 len(ans)==m:
            break
        if max(min(ans),aa)==y:
            ans.add(y)
            t+=bb
            y-=1
        else:
            for j in range(max(min(ans),aa),y+1):
                if j not in ans:
                    ans.add(j)
                    t+=bb
                    break
    print(ans)
    print(t)

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

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

taskDict = {}
for i in range(n):
  date, money = map(int, input().split())
  if date in taskDict:
    taskDict[date].append(money)
  else:
    taskDict[date] = [money]

taskDict2 = {}
# i -> 3,2,1,0
# m-i -> 1,2,3,4
for i in reversed(range(m)):
  taskDict2[i] = 0
  # i以下で作業が完了するtaskが存在するか判定
  if m-i in taskDict:
    for money in taskDict[m-i]:
      if taskDict2[i] < money:
        taskDict2[i] = money

result = 0
for i in taskDict2.values():
  result += i

print(result)

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
    ans[0]=1
    y=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 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(t)

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

Solution code:
import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

ans = 0
candidates = []
for reversed_day in range(1, m + 1):
  for i, cond in enumerate(conditions):
    if cond[0] > reversed_day:
      break
    tmp = conditions.pop(i)
    heapq.heappush(candidates, -tmp[1])

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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
                    break

    print(t)

if __name__=="__main__":
    sol()

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:
        aa*=-1
        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
                    break

    print(t)

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
# /usr/bin/python3

from heapq import heappush

def main():
  n, m = map(int, input().strip().split(' '))
  liAB = [tuple(map(int, input().strip().split(' '))) for _ in range(n)]
  liAB.sort(key=lambda x:x[0])

  k = 1
  top = []
  s = 0
  for a, b in liAB:
    if a >= m+1:
      break

    if k < a:
      if len(top) > a-k:
        s += sum(top[-(a-k):])
        del top[-(a-k):]
      else:
        s += sum(top)
        top = []
      k = a

    # top.append(b)
    heappush(top, b)


  top.sort()
  s += sum(top[-(m-k+1):])
  print(s)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:

import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    heapq.heappush(conditions[inputs[0]], -inputs[1])
  else:
    conditions[inputs[0]] = []
    heapq.heappush(conditions[inputs[0]], -inputs[1])

ans = 0
candidates = []
for reversed_day in range(1, m + 1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  if len(candidates) == 0:
    continue

  cnt, maxval, maxkey = 0, 0, 0
  for cands in candidates:
    if cands[0] > maxval:
      maxval = cands[0]
      maxkey = cnt
    cnt += 1
  ans -= heapq.heappop(candidates[maxkey])
  if len(candidates[maxkey]) == 0:
    del candidates[maxkey]
print(ans)

Submission status: Wrong Answer

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

days = [albeit[p][0] for p in range(N)]
reward = [albeit[q][1] for q in range(N)]


z = 1 #z日前
#M-z日目にどの仕事を請けるか
sum_r = 0

while M - z >= 0:
  if z in days:
    ind = days.index(z)
    sum_r += reward[ind]
    del days[ind]
    del reward[ind]
  elif min(days) < z:
    ind = max([s for s , t in enumerate(reward) if t == max(reward)])
    sum_r += reward[ind]
    del days[ind]
    del reward[ind]  
  z += 1

print(sum_r)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
albeit = [list(map(int, input().split())) for i in range(N)]
albeit = ['{0[0]:06d} {0[1]:05d}'.format(albeit[j])
          for j in range(N)]
albeit = [x.split() for x in sorted(albeit)]
albeit = [list(map(int, y)) for y in albeit]
albeit.reverse()


days = [albeit[p][0] for p in range(N)]
reward = [albeit[q][1] for q in range(N)]


z = 1 #z日前
#M-z日目にどの仕事を請けるか
sum_r = 0

while M - z >= 0:
  if z in days:
    ind = days.index(z)
    sum_r += reward[ind]
    del days[ind]
    del reward[ind]
  elif min(days) < z:
    ind = max([s for s , t in enumerate(reward) if t == max(reward)])
    sum_r += reward[ind]
    del days[ind]
    del reward[ind]  
  z += 1

print(sum_r)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
albeit = [input().split() for i in range(N)]
albeit = [' '.join(['0'*(6-len(albeit[j][0])) + albeit[j][0], 
                    '0'*(5-len(albeit[j][1])) + albeit[j][1]]) for j in range(N)]
albeit = [x.split() for x in sorted(albeit)]
albeit = [list(map(int, y)) for y in albeit]
albeit.reverse()


days = [albeit[p][0] for p in range(N)]
reward = [albeit[q][1] for q in range(N)]


z = 1 #z日前
#M-z日目にどの仕事を請けるか
sum_r = 0

while M - z >= 0:
  if z in days:
    ind = days.index(z)
    sum_r += reward[ind]
    del days[ind]
    del reward[ind]
  elif min(days) < z:
    ind = max([s for s , t in enumerate(reward) if t == max(reward)])
    sum_r += reward[ind]
    del days[ind]
    del reward[ind]  
  z += 1

print(sum_r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 21:35:06 2019

@author: doppe
"""

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

listA = []
listB = []
for i in range (0, N):
    A, B = map(int, input().split())
    listA.append([A,B])
    
sortA = sorted(listA, key=lambda k: k[0])
#sortA, sortB = sorted(listA), sorted(listB, key=lambda k: listA[k])

#print(sortB)
count = 1
ans = 0
taishoList = []
k = 0
while True:
    for i in range(k, N):
        if (count == sortA[i][0]):
            taishoList.append(sortA[i][1])
            k += 1
        else:
            break
        
    if len(taishoList) != 0:
        maxValue = max(taishoList)
        print(str(count) + ":" + str(maxValue))
        ans += maxValue
        taishoList.remove(maxValue)
    count += 1
    if (count > M):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
N, M = [int(x) for x in input().split()]
AB_list = sorted([input().split() for _ in range(N)], key=lambda x: int(x[0]))
print(AB_list)
h = []
ans = 0
for i in range(1, M+1):
    lst = AB_list[:]
    for A, B in lst:
        if (int(A) <= i):
            tmp = AB_list.pop(0)
            heapq.heappush(h, -1 * int(tmp[1]))
        else: break
    # print(AB_list, h)
    if (len(h)):
        ans += -1 * heapq.heappop(h)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
N, M = [int(x) for x in input().split()]
AB_list = sorted([input().split() for _ in range(N)], key=lambda x: int(x[0]))
print(AB_list)
h = []
ans = 0
for i in range(1, M+1):
    tmp = AB_list[:]
    for A, B in tmp:
        if (int(A) <= i):
            tmp = AB_list.pop(0)
            heapq.heappush(h, -1 * int(tmp[1]))
        else: break
    # print(AB_list, h)
    if (len(h)):
        ans += -1 * heapq.heappop(h)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from heapq import heappush, heappop

# initialize
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
day = m
all_salary = 0

hiyatoi = np.array(hiyatoi)
hiyatoi = hiyatoi[:,[1,0]]
hiyatoi = hiyatoi*(-1)
hiyatoi = tuple(map(tuple,hiyatoi))

hq = []

for index in range(n):
  heappush(hq,hiyatoi[index])
for index in range(n):
  salary,payday = heappop(hq)
  if payday*(-1)<=day:
    all_salary -= salary
    day -= 1
  if day == 0:
    break

print(all_salary)

Submission status: Wrong Answer

Solution code:
import numpy as np
from heapq import heappush, heappop

# initialize
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
day = m
all_salary = 0

hiyatoi = np.array(hiyatoi)
hiyatoi = hiyatoi[:,[1,0]]
hiyatoi = hiyatoi*(-1)
hiyatoi = tuple(map(tuple,hiyatoi))

hq = []

for index in range(n):
  heappush(hq,hiyatoi[index])
for index in range(n):
  salary,payday = heappop(hq)
  if payday*(-1)<=day:
    all_salary -= salary
    day -= 1

print(all_salary)

Submission status: Wrong Answer

Solution code:
import numpy as np
from heapq import heappush, heappop

# initialize
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
day = m
all_salary = 0

hiyatoi = np.array(hiyatoi)
hiyatoi = hiyatoi[:,[1,0]]
hiyatoi = hiyatoi*(-1)
hiyatoi = tuple(map(tuple,hiyatoi))

hq = []
temp = []

for index in range(n):
  heappush(hq,hiyatoi[index])

for index in range(n):
  salary,payday = heappop(hq)
  if payday*(-1)<=day:
    all_salary -= salary
  day -= 1

print(all_salary)

Submission status: Wrong Answer

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

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

L.sort(key = lambda x:(-x[1], -x[0]))

ans = 0
buffer = M - 1
m = [0] * M
while buffer >= 0:
    t = buffer
    for i in range(N):
        if buffer < 0:
            break
        d, p = L[i]
        if d + buffer <= M:
            ans += p
            buffer -= 1
            L[i] = (10 ** 18, 0)
    if t == buffer:
        buffer -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = {}
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if a in d1:
      d1[a].append(b)
    else:
      d1[a] = [b]
  result = 0
  d2 = {}
  maxb = -1
  maxbn = -1
  for i in _range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 0
        d2[j] += 1
        if j > maxb:
          maxbn = maxb
          maxb = j
    else:
      if _len(d2) == 0:
        continue
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
        maxbn = -1
      else:
        if maxbn != -1:
          maxb = maxbn
          maxbn = -1
        else:
          maxb = _max(d2.keys())
    else:
      d2[maxb] -= 1
  print(result)
main()

Submission status: Wrong Answer

Solution code:
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = {}
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if a in d1:
      d1[a].append(b)
    else:
      d1[a] = [b]
  result = 0
  d2 = {}
  maxb = -1
  maxbn = -1
  for i in _range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 0
        d2[j] += 1
        if j > maxb:
          maxbn = maxb
          maxb = j
    else:
      if _len(d2) == 0:
        continue
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
      else:
        if maxbn != -1:
          maxb = maxbn
          maxbn = -1
        else:
          maxb = _max(d2.keys())
    else:
      d2[maxb] -= 1
  print(result)
main()

Submission status: Wrong Answer

Solution code:
import itertools

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conf = [[int(x) for x in input().split()] for _ in range(n)]
# conf = sorted([[int(x) for x in input().split()] for _ in range(n)], reverse=True)

maxres = 0
for cc in itertools.permutations(conf, m):
  res = 0
  for i, c in enumerate(cc):
    if i + c[0] <= m:
      res = res + c[1]
  if res > maxres:
    maxres = res
print(maxres)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
#A = [0]*N
#B = [0]*N
#for i in range(N):
#  A[i], B[i] = map(int, input().split())
L = []
for i in range(N):
  L.append(list(map(int, input().split())) )  

answer = 0
var_a = 0
L.sort(reverse=True)
L.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

for i in range(N):
  if L[i][0] <= M-i+var_a:
    answer += L[i][1]
  else:
    var_a += 1

print(answer)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
ct = [0] * (10 ** 4 + 1)
cc = 0
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      ct[j] += 1
      if j > maxb:
        maxb = j
    cc += len(d1[i])
  else:
    if cc == 0:
      continue
  result += maxb
  ct[maxb] -= 1
  cc -= 1
  if ct[maxb] == 0:
    if cc == 0:
      maxb = -1
    else:
      for j in range(maxb - 1, -1, -1):
        if ct[j] != 0:
          maxb = j
print(result)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
ct = [0] * (10 ** 4 + 1)
cc = 0
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      ct[j] += 1
      if j > maxb:
        maxb = j
    cc += len(d1[i])
  else:
    if cc == 0:
      continue
  result += maxb
  ct[maxb] -= 1
  cc -= 1
  if ct[maxb] == 0:
    if cc == 0:
      maxb = -1
    else:
      for j in range(maxb, -1, -1):
        if ct[maxb] != 0:
          maxb = j
print(result)

Submission status: Wrong Answer

Solution code:
def merge(A, B, N):
    ia = 0
    for i in range(len(B)):
        b = B[i]
        while (ia < len(A) and A[ia] > b):
            ia += 1
            if (ia > N):
                break
        if (ia == len(A) - 1):
            A += B[i + 1:]
            break
        A.insert(ia, b)
    return A[:N]


def calc(N, M, AB):
    day2pay = {i: [0] for i in range(1, max([a for (a, b) in AB] + [M]) + 1)}
    for a, b in AB:
        for i in range(len(day2pay[a])):
            if (day2pay[a][i] <= b):
                day2pay[a].insert(i, b)
                break
    result = 0
    merged = []
    for m in range(1, M + 1):
        dpm = day2pay.pop(m)
        merged = merge(merged, dpm, M - m + 1)
        result += merged.pop(0)
    return result


(N, M) = tuple([int(s) for s in input().split(' ')])
AB = [tuple([int(s) for s in input().split(' ')]) for _ in range(N)]
print(calc(N, M, AB))

Submission status: Wrong Answer

Solution code:
import bisect
import time


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


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]]:
        d = A[ind_sorted[i]]-tmp_a
        tmp_money = sum(tmp_b_ls[-d:])
        money += tmp_money
        # 最大値以外を取り除く
        tmp_b_ls = tmp_b_ls[max(0,(M-1)-(len(tmp_b_ls)-d)):-d]
        tmp_a = A[ind_sorted[i]]
    bisect.insort(tmp_b_ls,B[ind_sorted[i]])

d = M+1-tmp_a
tmp_money = sum(tmp_b_ls[-d:])
money += tmp_money

print(money)

Submission status: Wrong Answer

Solution code:
import bisect
import time


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


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]]:
        d = A[ind_sorted[i]]-tmp_a
        tmp_money = sum(tmp_b_ls[-d:])
        print(d)
        print(tmp_b_ls)
        money += tmp_money
        tmp_b_ls = tmp_b_ls[:min(len(tmp_b_ls)-d,M-1)]
        tmp_a = A[ind_sorted[i]]
    bisect.insort(tmp_b_ls,B[ind_sorted[i]])

d = M+1-tmp_a
tmp_money = sum(tmp_b_ls[-d:])
money += tmp_money
print(d)
print(tmp_b_ls)

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, heapq


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    C = list(zip(A, B))
    C = sorted(C, reverse=True, key=lambda x: x[0])
    C = sorted(C, reverse=True, key=lambda x: x[1])
    day = 0
    ret = 0
    while day <= M+1:
        if len(C) == 0:
            print(ret)
            return
        (a, b) = C.pop(0)
        if a <= M - day:
            ret += b
        day += 1
    print(ret)
    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()