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 math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,m = get_nums_l()
jobs = list(map(lambda s:list(map(int,s.split(" "))), sys.stdin.readlines()))

jobs.sort(key=lambda job: job[0])
jobs.sort(key=lambda job: job[1], reverse=True)

mark = [True] * (m+1)
ans = 0
for job in jobs:
    nouki = job[0]
    if nouki <= m:
        if mark[nouki]:
            ans += job[1]
            mark[nouki] = False
        elif mark[m]:
            # にぶたん
            # left 既知の右端False
            left = nouki
            # right 既知の左端True
            right = m
            while(left < right-1):
                center = (left+right)//2
                if(mark[center]):
                    right = center
                else:
                    left = center
            ans += job[1]
            mark[right] = False

print(ans)

Submission status: Wrong Answer

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

ab = []

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

ab.sort(reverse=True)
index = 0
ans = 0

for i in range(M+1):
    flag = True
    while flag:
        if index >= N:
            flag = False
        elif i + ab[index][1] <= M:
            ans += ab[index][0]
            index += 1
            flag = False
        else:
            index += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M= map(int, input().split())
A = [[int(x) for x in input().split()] for _ in range(N)]
ans = 0
A.sort(key=lambda x:(x[1],x[0]), reverse=True)
for i in range(N):
    if A[i][0]<=M:
        ans += A[i][1]
        M = M-1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0],reverse=True)
ab.sort(key=lambda x:x[1],reverse=True)
l=[m-i for i in range(m)]
l.insert(0,0)
x=[]
for i in range(n):
    if ab[i][0]<=m and l[ab[i][0]]>0:
        x.append(ab[i])
        l[ab[i][0]]-=1
    else:
        continue
ans=0
for i in range(min(len(x),m)):
    ans+=x[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
arr = []
d = {}
for i in range(n):
    a,b = map(int,input().split())
    arr.append([a,b])
    if b not in d:
        d[b]=1
    else:
        d[b] += 1

arr.sort(key=lambda x:[x[1],x[0]])
arr.reverse()
# print(arr)
ans = 0

ind = 0
for i in range(m):
    rest = m-i
    while True:
        if arr[i][0] <= rest:
            ans += arr[i][1]
            ind += 1
            break
        else:
            ind += 1
            if ind > n-1:
                break
    if ind > n-1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[]
q=0
for i in range(n):
    p=[int(j) for j in input().split()]
    q=max(q,p[0])
    ab.append(p)
from operator import itemgetter

ab.sort(key=itemgetter(0))
ab.reverse()
ab.sort(key=itemgetter(1))
ab.reverse()

k=0
ans=0
l=[0 for i in range(q+1)]
import numpy as np
l=np.array(l)
for i in range(n):
    if l[ab[i][0]]<m-ab[i][0]+1:
        ans+=ab[i][1]
        a=np.array([1]*(ab[i][0]+1)+[0]*(q-ab[i][0]))
        l=l+a
        k+=1
    if k==m:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def cmp(a):
    return a[1]

def comp(a):
    return a[0]

def f(a,n,m):
    sum = 0
    cnt = 0
    for i in range(n):
        if(cnt+a[i][0]<=m):
            sum+=a[i][1]
            cnt+=1
    return sum

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
b = sorted(a, key=comp, reverse = True)
b = sorted(b, key=cmp, reverse = True)
a = sorted(a, key=cmp, reverse = True)
a = sorted(a, key=comp, reverse = True)

ans = max(f(a,n,m),f(b,n,m))
print(ans)

Submission status: Wrong Answer

Solution code:
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] = [-B, -A]
l.sort()
ans = 0
today = 0
for i in range(N):
    if today - l[i][1] <= M:
        ans -= l[i][0]
        today += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
box=[list(map(int,input().split())) for i in range(n)]
day={}
for i in box:
    if i[0] in day:
        day[i[0]] +=[i[1]]
    else:
        day[i[0]]=[i[1]]
count=0
point=0

while point<m:
    score=[0,0]
    for v,t in day.items():
        if v+point<=m:
            if len(day[v])>0:
                if max(t)>=score[1] and v>=score[0]:
                    score=[v,max(t)]
    count +=score[1]
    try:
        day[score[0]].remove(score[1])
    except:break
    point +=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
AB_dict = defaultdict(list)
AB = sorted([tuple(map(int, input().split())) for i in range(N)], reverse=True, key=lambda x: x[0])
AB = sorted(AB, reverse=True, key=lambda x: x[1])
EF = [M-i+1 for i in range(10**5+1)]
m = 0
sm = 0
max_sm = sum(range(1, M+1))
ans = 0
for i in range(N):
    Ai, Bi = AB[i]
    if EF[Ai] >= 1 and sm+Ai <= max_sm:
        ans += Bi
        EF[Ai] -= 1
        sm += Ai
        m += 1
    if m == M:
        break
print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        AB.append((a, b, a * b))

N = len(AB)

AB.sort(key=lambda x: x[2], reverse=True)
limit = M
reward = 0
for a, b, ab in AB:
    if a <= limit:
        reward += b
        limit -= 1
print(reward)

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))



N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())

#ab=sorted(ab,key=lambda x:x[1],reverse=True)
ab=sorted(ab,key=lambda x:x[1])
#print(ab)
now=0
res=0
while True:
    try:
        sab=ab.pop()
    except:
        break
    #print(now,sab)
    if sab[0]+now<=M:
        res+=sab[1]
    
    now+=1

print(res)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB_list = [tuple(map(int, input().split())) for i in range(N)]
               
# print(AB_list)
sorted_AB_list = sorted(AB_list, key=lambda x:x[0], reverse=True)
sorted_AB_list = sorted(sorted_AB_list, key=lambda x:x[1], reverse=True)

# sorted_AB_list = sorted(AB_list, key=lambda x:x[1], reverse=True)

# for A, B in sorted_AB_list:
#   print(A, B)

money = 0

for i in range(M)[::-1]: # 残り日数
  remain_days = i+1
  
  for A, B in sorted_AB_list:
    if A <= remain_days:
      # print(A, B)
      money += B
      sorted_AB_list.remove((A, B))
      break
      
print(money)

Submission status: Wrong Answer

Solution code:
# 2019 8/10
# ABC137 D Summer Vacation

info = []
reword = 0
day = 0

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

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

info.sort(reverse=True)
print(info)

for i in range(N):
    if day > M:
        break

    if info[i][1] + day <= M:
        reword += info[i][0]
        day += 1


print(reword)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
def KnapSack(val, wt, n, W): 
      
    # array to store final result 
    # dp[i] stores the profit with KnapSack capacity "i" 
    dp = [0]*(W+1); 
  
    # iterate through all items 
    for i in range(n): 
          
        #traverse dp array from right to left 
        for j in range(W,wt[i],-1): 
            dp[j] = max(dp[j] , val[i] + dp[j-wt[i]]); 
              
    '''above line finds out maximum of dp[j](excluding ith element value) 
    and val[i] + dp[j-wt[i]] (including ith element value and the 
    profit with "KnapSack capacity - ith element weight") *'''
    return dp[W];
n,m=map(int,raw_input().split())
# t=int(raw_input())
f=defaultdict(int)
a=[]
b=[]
for i in range(n):
    c,d=map(int,raw_input().split())
    a.append((d,c))
a.sort()
a=a[::-1]
ans=0

# print a
for i in a:

    if(m+1-i[1]>0):
        ans=ans+i[0]
        m=m-1
print ans

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
ans=0
AB=[]
for _ in range(N):
    A,B=map(int,input().split())
    AB.append([A,-B])
AB.sort(key=lambda x:(x[1],x[0]))
D=0
memo=0
while D<=M:
    A,B=AB[memo]
    if D<A:
        pass
    else:
        ans-=B
        memo+=1
    D+=1
print(ans)

Submission status: Wrong Answer

Solution code:
num, day = [int(x) for x in input().split()]

worklist = [[] for i in range(day+4)]

for i in range(num):
  d, m = [int(x) for x in input().split()]
  if d <= day:
    worklist[d-1].append(m)

ans = 0

canworklist = []

for i in range(day):
  canworklist += worklist[i]
  if canworklist:
    canworklist.reverse()
    ans += canworklist.pop(0)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:(x[1],x[0]),reverse=True)
# AB = sorted(AB, key= lambda x:x[0],reverse=True)
cnt=0
# for i, ab in enumerate(AB):
#     a = ab[0]
#     b = ab[1]
#     if i + a <=m:
#         cnt+=b
#     else:

i = 0
j = 0
while i < m:
    if j == n:
        break
    a =AB[j][0]
    b =AB[j][1]
    j+=1
    if i + a <=m:
        cnt += b
        i+=1
    else:
        pass

print(cnt)

Submission status: Wrong Answer

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

# print(N, M, AB)
AB.sort(key=lambda ab: ab[0], reverse=True)
AB.sort(key=lambda ab: ab[1], reverse=True)
# print(AB)

index = 0
ans = 0
for i in range(M):
    remain = M - i
    while True:
        # print(index)
        ab = AB[index]
        if ab[0] <= remain:
            index += 1
            ans += ab[1]
            break
        index += 1
        if index >= N:
            break
    if index >= N:
        break

print(ans)

Submission status: Wrong Answer

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

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

jobs = []
for i in range(N):
    (A, B) = map(int, input().split(" "))
    jobs.append({"payday": A, "salary": B})


# Day i には、給料(salary)が最も大きい かつ 支払日(payday)が Day M"以前"のモノを選ぶ。
# ただし、複数ある場合は、最もpaydayが大きいモノを選ぶ。

total = 0
for i in range(1, M + 1):   # 1 〜 M
    try:
        max_salary = max([job["salary"] for job in jobs
                          if job["payday"] + i <= 1 + M])
    except ValueError:
        # もう仕事がない
        break

    max_payday = max([job["payday"] for job in jobs
                      if job["salary"] == max_salary])

    total += max_salary
    jobs.remove({"payday": max_payday, "salary": max_salary})

print(total)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB_sort = sorted(AB,key=lambda x: x[0],reverse=True)
AB_sort2 = sorted(AB_sort,key=lambda x: x[1],reverse=True)
limit = M * (M+1) // 2
max_day = M
max_point = 0
for i in range(N):
    if AB_sort2[i][0] == max_day:
        max_point += AB_sort2[i][1]
        max_day -= 1
    elif AB_sort2[i][0] > max_day:
        continue
    elif AB_sort2[i][0] < max_day:
        max_point += AB_sort2[i][1]
        max_day -= 1
print(max_point)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import heapq as hq
n, m = map(int, input().split())

jobs = [[] for _ in range(m+1)]

for _ in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    hq.heappush(jobs[a], -b)

pay = 0
work_cand = []
for i in range(m + 1):
    add_jobs = jobs[i]
    if len(add_jobs) != 0:
        work_cand = list(hq.merge(work_cand, add_jobs))

    if len(work_cand) == 0:
        continue

    pay -= hq.heappop(work_cand)

print(pay)

Submission status: Wrong Answer

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

L = sorted(L)

ans = 0
for i in range(0, M):
    dead = M - i
    if len(L) == 0:
        break
    
    while len(L) != 0:
        m = L.pop(-1)
        if m[1] <= dead:
            ans += m[0]
            break
        else:
            continue

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
jobs = []
for _ in range(n):
    a, b = map(int, input().split())
    jobs.append((a, b))
jobs.sort(key=lambda x: x[0], reverse=True)
jobs.sort(key=lambda x: x[1], reverse=True)
ans = 0
d = 0
for job in jobs:
    if job[0] <= m - d:
        ans += job[1]
        if m - d < 0:
            break
        d += 1
print(ans)

Submission status: Wrong Answer

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

work = []
for i in range(N):
    work.append(list(map(int,input().split())))
work.sort(key = lambda x : x[1])
work.reverse()

ans =  0
count = 0
for i in range(N):
    count = i + work[i][0]
    if (count <=M):
        ans = ans+work[i][1]
        
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
D = []
for _ in range(N):
    a, b = map(int,input().split())
    D.append((b, a))
D.sort(reverse=True)

ans = 0
i = 0
j = 0
while i < N:
    b, a = D[i]
    if j + a <= K:
        ans += b
        j += 1
    i += 1

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    nums = list(map(int, input().split()))
    E.append((nums[1], nums[0]))
E = sorted(E)

ans = 0
for i in range(M):
    while len(E) > 0:
        e = E.pop()
        if i + e[1] <= M:
            ans += e[0]
            break
print(ans)

Submission status: Wrong Answer

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

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

#print(AB)

day = 0
ans = 0
p = 0

while day <= M:
    if p < N:
        if p + AB[p][1] <= M:
            ans += AB[p][0]
        p += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = list(map(int,input().split()))
a = defaultdict(int)
for u in range(n):
    b,v=list(map(int,input().split()))
    if(b>m):
        continue
    else:
        if(a[b]<v):
            a[b] = v
print(sum(a.values()))

Submission status: Wrong Answer

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

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

def obj(x):
    return (x[1] + x[0]/(10**5))*-1
xs = sorted(xs,key=lambda x:obj(x))
#print(xs)

m = 0
c = 0
income = 0
while True:
    if xs[c][0] <= M-m:
        income += xs[c][1]
        m+=1
    #print('c', c, income, M)
    if c == len(xs)-1:
        break
    if m == M:
        break
    c+=1
print(income)

Submission status: Wrong Answer

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

score_list = [[] for i in range(M+1)]


for ab in ab_list:
    if ab[0] <= M:
        score_list[ab[0]].append(ab[1])

ans = 0
for i in range(0, M+1):
    if len(score_list[i]) == 0:
        continue
    scores = deque(sorted(score_list[i]))
    ans += scores.pop()
    if i < M and len(scores) > 0:
        score_list[i+1].append(scores.pop())

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
se = sorted(e,key=lambda l:l[1],reverse=True)
sse = sorted(se,key=lambda l:l[0],reverse=True)
day = 0
ans = 0
for work in sse:
    if work[0]<=m-day:
        ans+=work[1]
        day+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = {}
for i in range(n):
    a,b = map(int,input().split())
    if b in ab:
        ab[b].append(a)
    else:
        ab[b] = [a]
#print(ab)
ans = 0
day = 0
for i in range(max(ab)+1)[::-1]:
    if i in ab:
        a = ab[i]
        #print(i,ab[i])
        for j in sorted(a,reverse=True):
            if m-day >= j:
                ans += i
                day += 1
            #print("ans={0},day={1}".format(ans,day))
print(ans)

Submission status: Wrong Answer

Solution code:
num, day = [int(x) for x in input().split()]

worklist = [[] for i in range(day)]

for i in range(num):
  d, m = [int(x) for x in input().split()]
  if d < day:
    worklist[d-1].append(m)

ans = 0

canworklist = []

for i in range(day):
  canworklist += worklist[i]
  if canworklist:
    mm = max(canworklist)
    ans += mm
    canworklist.remove(mm)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = [int(x) for x in input().split()]
profits = []
for _ in range(n):
	a,b = [int(x) for x in input().split()]
	profits.append((b,a))
day = 0
pro = 0
profits.sort()
for t in profits[::-1]:
	if day+t[1] <= m:
		pro += t[0]
		day += 1
print(pro)

Submission status: Wrong Answer

Solution code:
import math

N, M = list(map(int, input().split(" ")))
AB = [list(map(int, input().split(" "))) for _ in range(N)]


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

idx = 0
p = 0
for i in range(M):
  d = M - i
  if idx >= N:
    break
  while idx < N:
    if AB[idx][0] > d:
      idx += 1
      continue
    p += AB[idx][1]
    idx += 1
    break
print(p)

Submission status: Wrong Answer

Solution code:
def sol():
    n,m=map(int,input().split())
    d=[]
    ans=[0]*(m+1)
    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]=bb
            y-=1
        else:
            for j in range(max(x,aa),y):
                if ans[j]==0:
                    ans[j]=bb
                    if j==x: x+=1
                    if j==y: y-=1
                    break

    print(sum(ans))

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A_B=[list(map(int,input().split())) for _ in range(N)]
A_B.sort(key=lambda x:x[1],reverse=True)
for i in range(N-1):
    if A_B[i][1]==A_B[i+1][1]:
        tmp=A_B[i+1][0]
        A_B[i+1][0]=A_B[i][0]
        A_B[i][0]=tmp
NUM=N
ans=0
c=0
while True:
    tmp=A_B.pop(0)
    if tmp[0]<=M:
        ans+=tmp[1]
        M-=1
    else:
        pass
    c+=1
    if c==(NUM):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
f = []
for _ in range(n):
    x, y = list(map(int, input().split()))
    f.append({'a':x, 'b':y})
    
f = sorted(f, key = lambda i: (-i['b'], -i['a'])) 
# print(f)
cnt = 0
ans = 0
for x in f:
    if x['a'] <= m - cnt:
        ans += x['b']
        cnt += 1
    if cnt >= m:
        break

print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

d = defaultdict(list)

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


works = []
for k, v in d.items():
    d[k] = sorted(d[k], reverse=True)
    works.extend(d[k][:M-k+1])

works = sorted(works, reverse=True)

print(sum(works[:M]))

Submission status: Wrong Answer

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

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

A.sort(reverse = True)
A.sort(key = lambda x:-x[1])

ans = 0
while(M):
    i = 0
    while(i < len(A)):
        if A[i][0] <= M:
            ans += A[i][1]
            del A[i]
            break
        else:
            del A[i]
            i -= 1
        i += 1
    M -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
D = []
for _ in range(N):
    a, b = map(int,input().split())
    D.append((b, a))
D.sort(reverse=True)

ans = 0
i = 0
while i < N:
    b, a = D[i]
    if i + a <= K:
        ans += b
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0],reverse=True)
ab.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(n):
    if ab[i][0]<=m:
        ans+=ab[i][1]
        m-=1
    else:
        continue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    work = [None for _ in range(N)]
    for i in range(N):
        a, b = map(int, input().split())
        work[i] = [-b, M - a]
    work.sort()
    #print(work)

    id = 0
    ans = 0
    for i in range(M):
        if id == N: break
        else:
            while work[id][1] < i and id < N:
                id += 1
                if id == N: break
            if id < N:
                ans -= work[id][0]
                id += 1
            else: break
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

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

A.sort(key=lambda B : (B[1], B[0]), reverse=True)

day = 0
ans = 0
for a, b in A :
    if a + day <= M :
        ans += b
        day += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re
import bisect

BIGNUM = 10 ** 9 + 7

def main():
    N, M = map(int, input().split())
    #N = int(input())
    #Hs = list(map(int, input().split()))

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

    works = sorted(works, key=lambda w: (w[1], w[0]), reverse=True)

    m = 0
    reward = 0
    for i in range(len(works)):
        A, B = works[i]
        if m + A <= M:
            reward += B
            m += 1

    print(reward)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])
A = sorted(A, key = lambda x : x[0], reverse = True)
# print(A)
ans = 0

for i in range(M - 1, -1, -1):
    maximum_rwd = 0
    maximum_id = 0
    for j in range(len(A)):
        if A[j][0] > M - i:
            break
        # A[j]報酬までの時間、
        elif maximum_rwd < A[j][1]:
            maximum_id = j
            maximum_rwd = A[j][1]
    if maximum_rwd > 0:
        ans += maximum_rwd
        A.pop(maximum_id)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
c={}
for _ in range(n):
  a,b=[int(i) for i in input().split()]
  if a in c:
    c[a].append(b)
  else:
    c[a]=[b]
k=0
l=[]
for i in range(m+1):
  if i in c:
    j=sorted(c[i],reverse=True)
    if l:
      if max(j)>l[0]:
        k+=max(j)
        if len(j)>1:
          l=l+j[1:]
      else:
        k+=max(l)
        del l[l.index(max(l))]
        l=l+j
    else:
      k+=j[0]
      l=j[1:]
  else:
    if l:
      k+=max(l)
      del l[l.index(max(l))]
  if len(l)>m:
    l=l[:m]
print(k)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
d = [tuple(map(int,input().split())) for i in range(n)]
d.sort(key = lambda x:x[0],reverse=True)
d.sort(key=lambda x:x[1],reverse=True)

cur_date = 0
hoshu = 0
for job in d:
    if job[0] + cur_date <= m:
        hoshu+=job[1]
        cur_date+=1
print(hoshu)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
works = [[] for _ in range(10**5+1)]
for i in range(n):
    a, b = map(int, input().split())
    works[a].append(b)
reward = 0
now_works = [0 for _ in range(10**4+1)]
now_max = 0
for i in range(m+1):
    for kingaku in works[i]:
        now_works[kingaku] += 1
        if now_max < kingaku:
            now_max = kingaku
    if now_max == 0:
        continue
    reward += now_max
    now_works[kingaku] -= 1
    if now_works[kingaku] == 0:
        for k in reversed(range(0, now_max)):
            if now_works[k] > 0:
                now_max = k
                break
        else:
            now_max = 0
print(reward)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect



def main():
    num, max_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    data.sort(key=lambda x:(-x[1]))


    visit = [0 for i in range(max_num + 1)]

    ans = 0

    for i in range(num):
        day, value = data[i]
        ind_lim = max_num - day + 1
        ind_insert = bisect.bisect_left(visit[:ind_lim], 1) - 1
        if ind_insert >= 0:
            visit[ind_insert] = 1
            ans += value

    print(ans)







if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]
# from math import factorial
# def nCr(n, r):
#   return factorial(n) // factorial(r) // factorial(n - r)

N, M = [int(i) for i in input().split(" ")]
ABs = []
for _ in range(N):
   A, B = [int(i) for i in input().split(" ")]
   ABs.append([A, B])
ABs.sort(key=lambda ab: (-ab[1], -ab[0]))
ans = 0
j = 0
for i in range(M):
  k = j
  while k < len(ABs):
    a, b = ABs[k]
    if i + a <= M:
       ans += b
       j = k + 1
       break
    k += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * size
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


N, M = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

AB.sort(key=lambda ab: (-ab[1], ab[0]))
bit = BinaryIndexedTree(size=M)

ans = 0
for a, b in AB:
    # 入れられる？
    cap = M - a - bit.sum(M - a) + 1
    if cap > 0:
        ans += b
        # どこに入れよう？
        ok = 0
        ng = M - a + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if M - a - bit.sum(mid) + 1 == cap:
                ok = mid
            else:
                ng = mid
        bit.add(ok, 1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=list(tuple(map(int,input().split())) for _ in range(N))
L.sort(key=lambda x: x[1]*10**5+x[0], reverse=True)
ans=0
flg=0
for i in range(M):
    while len(L)!=0:
        a,b=L.pop(0)
        if a+i<=M:
            break
        if len(L)==0:flg=True
    if flg:break
    ans+=b
    if len(L)==0:break
print(ans)

Submission status: Wrong Answer

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

ab_sort = sorted(ab, key=lambda x:x[1])
for i in range(len(ab_sort)):
  ab_sort[i][0] = M - ab_sort[i][0]

score = 0
while len(ab_sort) != 0:
  while len(ab_sort) != 0:
    p = ab_sort.pop()
    if p[0] < 0:
      continue
    else:
      score += p[1]
      break
  for i in range(len(ab_sort)):
    ab_sort[i][0] -= 1
    
print(score)

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[1], x[0]), 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())
BillDue = [0]*N
for i in range(N):
    A,B = map(int,input().split())
    BillDue[i] = (B,A)

BillDue.sort()

#print(BillDue)

ans = 0
day = 0
while BillDue:
    bi,du = BillDue.pop()
    if day + du <= M:
        day += 1
        ans += bi

print(ans)