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())
X = []
for _ in range(n):
    a, b = map(int, input().split())
    if m-a>=0:
        X += [(-b, m-a+1)]

X = sorted(X)
ans = [0]*m
ansx = 0

for ax, bx in X:
    if ans[-bx]==0:
        ans[-bx] = 1
        ansx -= ax
    elif ans[-bx]==1:
        if 0 in ans[-bx:]:
            ind = ans[-bx:].index(0)
            ans[ind] = 1
            ansx -= ax

print(ansx)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: -x[0])
ab.sort(key = lambda x: -x[1])
q, cnt, ans = [], 0, 0
for i, (a, b) in enumerate(ab):
    if cnt == M:
        break
    if a+cnt <= M:
        ans += b
        cnt += 1
        heappush(q, [-a, cnt])
    else:
        while len(q):
            _a, j = heappop(q)
            if -_a+cnt <= M and a+j <= M:
                ans += b
                cnt += 1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
lst = sorted(lst, key=lambda x: x[1])
lst = sorted(lst, key=lambda x: x[0], reverse=True)
d = m - 1
r = [0] * m
for i in range(n):
    p = lst.pop()
    for j in range(p[0]-1, m):
        if r[j] < p[1]:
            r[j] = p[1]
            break
print(sum(r))

Submission status: Wrong Answer

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


n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    if(x<=m):a.append((x, y))
b = sorted(sorted(a, key=lambda x: x[0], reverse=True), key=lambda x: x[1], reverse=True)
c = sorted(sorted(a, key=lambda x: x[1], reverse=True), key=lambda x: x[0], reverse=True)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#import sys
#N = int(input())
N, M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB, key = lambda x : x[0], reverse=True)
AB = sorted(AB, key = lambda x : x[1], reverse=True)
D = {}
#print(AB)
hou = 0
nokori = M
for i in range(N)  :
    ab = AB[i]
    if ab[0] <= nokori :
        hou += ab[1]
        nokori -= 1
print(hou)
#for m in range(M) :

#sys.exit()

Submission status: Wrong Answer

Solution code:
import copy

def get_greedy_pay(arbeits, dones, worklen):
    works = arbeits.get(worklen, [])
    done = dones.get(worklen, 0)
    if len(works) <= done:
        return -999
    else:
        return works[done]

counts, maxday = map(int, input().split())
arbeits = {}
days = set()

for i in range(counts):
    a, b = map(int, input().split())
    adays = arbeits.get(a, [])
    adays.append(b)
    adays.sort(reverse=True)
    #print("{}".format(adays))
    arbeits[a] = adays
    days.add(a)

#print("{}".format(arbeits))


rewards = [0]
plans = [{}]
for i in range(maxday):
    day = i + 1
    candlen = -1
    max_pay = -1
    for worklen in days:
        candday = day - worklen
        if candday >= 0:
            pay = get_greedy_pay(arbeits, plans[candday], worklen)
            if max_pay < pay:
                max_pay = pay
                candlen = worklen
    if max_pay > 0:
        plan = copy.copy(plans[day-1])
        plan[candlen] = plan.get(candlen, 0) + 1
        plans.append(plan)
        reward = rewards[day - 1]
        reward = reward + max_pay
        rewards.append(reward)
    else:
        plan = copy.copy(plans[day-1])
        plans.append(plan)
        reward = rewards[day-1]
        rewards.append(reward)
    #print("{}".format(rewards))
    #print("{}".format(plans))

print("{}".format(rewards[maxday]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

total = 0
for i in range(m):
    X = [x for x in X if x[0] + i <= m]
    X = sorted(X, key = itemgetter(1, 0), reverse = True)

    if X:
        total += X[0][1]
        X.remove(X[0])
    else:
        break

print(total)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
lst = sorted(lst, key=lambda x: x[1])
lst = sorted(lst, key=lambda x: x[0], reverse=True)
d = m - 1
r = [0] * m
for i in range(n):
    p = lst.pop()
    for j in range(p[0]-1, m):
        if r[j] < p[1]:
            r[j] = p[1]
            break
print(r)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    Q = defaultdict(list)
    Q2 = []
    for a, b in zip(A, B):
        heapq.heappush(Q[a], -b)
    
    for a in Q.keys():
        rank = M-a+1
        for i, b in enumerate(Q[a]):
            if i >= rank:
                break
            score = i + a
            Q2.append((score, b))
    Q2.sort()

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


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

table.sort(key=lambda x:x[1], reverse=True)
count = [0]*M
ans = 0
cnt = 0

for i in range(N):
    a, b = table[i]
    if a > M:
        break
    if count[a-1] >= M-a+1 or cnt >= M:
        continue
    ans += b
    cnt += 1
    for j in range(a):
        count[i] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
L = [list(map(int,input().split())) for k in range(N)]
L = sorted(L,key = lambda x: (-x[1],-x[0]))

ans = 0
c = 0
for k in range(N):
    if L[k][0] <= M:
        ans += L[k][1]
        c += 1
        if L[k][0] == M:
            M -= 1
    if c == M:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
"""
AtCoder
    :author: vierbein
"""
from __future__ import absolute_import, division, print_function

# import itertools as it
# import collections
import sys


def pp(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


N, M = map(int, input().split())
pairs = [[int(s) for s in input().split()] for _ in range(N)]
pairs = [(b, M - a) for (a, b) in pairs if a <= M]
pairs = sorted(pairs, key=lambda tup: (-tup[0], tup[1]))

res = 0
idx = 0
for (point, remaining) in pairs:
    if idx <= remaining:
        res += point
        idx += 1

    if idx == N:
        break

print(res)

Submission status: Wrong Answer

Solution code:
import sys

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if b in dic:
    pass
  else:
    dic[b] = []
  
  dic[b].append(a)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

for key in dic.keys():
  lst = dic[key]
  lst = sorted(lst,reverse=True)
  for i in lst:
    tmp = i
    if tmp <= m:
      count += key
      m -= 1
      if m == 0:
        print(count)
        sys.exit()
        
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline--------------------------------------------
    N,M = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    AB.sort(key = lambda x:x[0],reverse = True)
    AB.sort(key = lambda x:x[1],reverse = True)
    ans = 0
    total = M
    for i in range(N):
        if AB[i][0] <= total:
            ans += AB[i][1]
            total -= 1
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Wrong Answer

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

d = defaultdict(list)

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


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

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

print(sum(works[:M]))

Submission status: Wrong Answer

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

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

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

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

    print(ans)


if __name__ == '__main__':
    p_d()

Submission status: Wrong Answer

Solution code:
import bisect
n, m = [int(i) for i in input().split()]
d = []
for i in range(n):
    a, b = [int(_) for _ in input().split()]
    d.append([a, b])

d.sort(reverse=True)
l = [-1 for i in range(m+1)]
for i in range(n):
    if d[i][0] <= m and l[d[i][0]] == -1:
        l[d[i][0]] = i
ans = 0
cand = []
key = []
for i in range(1, m+1):
    idx = bisect.bisect_left(cand, d[l[i]][1])
    if l[i] != -1 and idx == len(cand):
        ans += d[l[i]][1]
        if l[i] + 1 < n and d[l[i]+1][0] == d[l[i]][0]:
            idx = bisect.bisect_left(cand, d[l[i]+1][1])
            cand.insert(idx, d[l[i]+1][1])
            key.insert(idx, i)
            l[i] += 1
    else:
        if len(cand) > 0:
            ans += cand[-1]
            if l[key[-1]] + 1 < n and d[l[key[-1]]+1][0] == d[l[key[-1]]][0]:
                idx = bisect.bisect_left(cand, d[l[key[-1]]+1][1])
                cand[-1] = d[l[key[-1]]+1][1]
                l[key[-1]] += 1
            else:
                del cand[-1]
                del key[-1]
        if l[i] != -1:
            idx = bisect.bisect_left(cand, d[l[i]][1])
            cand.insert(idx, d[l[i]][1])
            key.insert(idx, i)
print(ans)

Submission status: Wrong Answer

Solution code:
P = []
n, m = map(int, input().split())
ans = 0
for _ in range(n):
    a,b = map(int, input().split())
    P.append([a,b])
P = sorted(P, key= lambda x: [x[0]*x[1],x[1]], reverse=True)

for i,j in P:
    if i > m:
        continue
    ans += j
    m -= 1
    if m == 0:
        break
print(ans)

Submission status: Wrong Answer

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

C = [[0,0] * x for x in range(N)] 
for i in range(N):
  C[i] = list(map(int, input().split()))

C.sort(key=lambda x: x[1],reverse=True)
B =[0 * x for x in range(N)]
for i in range(min(N,M)):
  j = N - C[i][0]
  if j >= 0:
#    print (i, j ,C[i][0], C[i][1])
    while j >= 0:
#      print (B)
      if B[j] == 0:
        B[j] = C[i][1]
        break
      else:
        j -= 1
print(sum(B))

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)
    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+1):
                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(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))
ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

ans = 0
for i in ab:
    if i[0] <= m:
        ans += i[1]
        m -= 1
        if m < 0:
            break
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
    if i + int(job[i][0]) <= m:
        ans += int(job[i][1])
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    N, M = [int(f) for f in input().split()]
    v = []
    for _ in range(N):
        A, B = [int(f) for f in input().split()]
        if A > M:
            continue
        v.append((A, B))

    money = 0
    for day in range(M):
        _tmp = [f[1] for f in v]
        if _tmp == []:
            break
        m = max(_tmp)
        lst = [f[0] for f in v if f[1] == m]
        if not lst == []:
            d = max(lst)
            money += m
            print(m, d)
            v = [f for f in v if f[0] < M-(day) and ( not f[0] == d or not f[1] == m)]
            continue
        v = [f for f in v if f[0] < M-(day+1)]

    print(money)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
P = []
n, m = map(int, input().split())
ans = 0
for _ in range(n):
    a,b = map(int, input().split())
    P.append([a,b])
P = sorted(P, key= lambda x: [x[0]*x[1],x[1]], reverse=True)
print(P)

for i,j in P:
    if i > m:
        continue
    ans += j
    m -= 1
    if m == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))
ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

ans = 0
print(ab)
for i in ab:
    if i[0] <= m:
        ans += i[1]
        m -= 1
        if m < 0:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if b in dic:
    pass
  else:
    dic[b] = []
  
  dic[b].append(a)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

for key in dic.keys():
  lst = dic[key]
  lst = sorted(lst,reverse=True)
  for i in lst:
    tmp = i
    if tmp <= m:
      count += key
      m -= 1
      print(key)
      if m == 0:
        print(count)
        sys.exit()
        
print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l = [[int(a) for a in input().split()] for i in range(N)]
l = sorted(l, key=lambda x: (x[0], x[1]))
l1 = []
l2 = []
for a, b in l:
    l1.append(a)
    l2.append(b)

ans = 0
j = N-1
M += 1

from bisect import bisect

for i in range(1, M+1):
    k = bisect(l1, M-i, 0, j)
    if k == 0:
        break
    if l1[k] > M - i:
        k -= 1
    ans += l2[k]
    j = k

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

#tasks = [[] for i in range(21)]
tasks = [[] for i in range(10001)]
for n in range(N):
	A,B = map(int,input().split())
	tasks[B].append(A)
for t in tasks:
	t.sort(reverse=True)
#print(tasks,file=sys.stderr)

ans = 0
days = M
gain = len(tasks)-1
while 1<=gain:
	for d in tasks[gain]:
		#print('gain={} day={}'.format(gain,d))
		if d<=M:
			#print('\t get! {}'.format(d))
			ans += gain
			M -= 1
	gain -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
work = []
for i in range(n):
    _a, _b = list(map(int, input().split()))
    work.append({"duration": _a, "payment": _b})
work = sorted(work, key=lambda x: (x["payment"], x["duration"]))
p = 0
for i in range(m, 0, -1):
    if len(work) == 0:
        break
    w = work.pop(-1)
    while w["duration"] > i:
        if len(work) == 0:
            break
        w = work.pop(-1)
    else:
        p = p + w["payment"]
print(p)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(str,input().split())) for l in range(n)]
ab_s=sorted(ab,key=lambda x:x[1],reverse=True)
ct=0
j=0
for i in range(int(m)):
    if m>int(ab_s[j][0]):
        ct+=int(ab_s[j][1])
        j+=1
    else:break
print(ct)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())  # N件のアルバイト, M日後までの報酬
hoge = M+1
arubaito = [list(map(int, input().split())) for _ in range(N)]  # A日後に, B円報酬がもらえる。

arubaito = sorted(arubaito, key=lambda x: (x[1], x[0]), reverse=True)  # 報酬順にソート
ans = 0
for i in range(len(arubaito)):
    if hoge == arubaito[i][0]:
        continue
    if hoge > arubaito[i][0]:
        ans += arubaito[i][1]
        hoge -= 1  # 日雇いアルバイトしたなら日付を進める

print(ans)

Submission status: Wrong Answer

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

d = 0
ans = 0

ps.sort()

for i in ps[::-1]:
    if d + i[1] <= m:
        ans += i[0]
        d += 1
print(ans)

Submission status: Wrong Answer

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

lst = [list(map(int, input().split())) for s in range(N)]

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


r = 0
for m in range(M):

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

    if len(lst) == 0:
        break

print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N , M = (int(i) for i in input().split())  
A = [[int(i) for i in input().split()] for i in range(N)]
A = sorted(A, key=lambda x: x[0], reverse=True) 
A = sorted(A, key=lambda x: x[1], reverse=True) 
count = 0
j = 0
while M >= 1 and j <= N-1:
  if M+1 >= A[j][0]:
    count += A[j][1]
    j = j + 1
    M = M - 1
  else:
    j = j + 1
print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())  # N件のアルバイト, M日後までの報酬
hoge = M+1
arubaito = [list(map(int, input().split())) for _ in range(N)]  # A日後に, B円報酬がもらえる。

arubaito = sorted(arubaito, key=lambda x: (x[1], x[0]), reverse=True)  # 報酬順にソート
print(arubaito)
ans = 0
for i in range(len(arubaito)):
    if hoge == arubaito[i][0]:
        continue
    if hoge > arubaito[i][0]:
        ans += arubaito[i][1]
        hoge -= 1  # 日雇いアルバイトしたなら日付を進める

print(ans)

Submission status: Wrong Answer

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

AB = []
for i in range(N):
    Ai,Bi = map(int,input().split())
    AB.append([Ai,Bi])

AB.sort(key=itemgetter(1),reverse=True)
AB.sort(key=itemgetter(0))
from heapq import heappush, heappop
hq = []
i = 0
now = 1
ans = 0
while True:
    if i == N:
        if now <= M:
            if len(hq) == 0:
                break
            ans -= heappop(hq)
            now += 1
            continue
        else:
            break
    if AB[i][0] == now:
        heappush(hq,-AB[i][1])
        i += 1
        continue
    else:
        if len(hq) == 0:
            now += 1
            continue
        ans -= heappop(hq)
        now += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))
ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

ans = 0
for i in ab:
    if i[0] < m:
        ans += i[1]
        m -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
a_list = []
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        a_list.append([a, b])
a_list = sorted(a_list, key=lambda x: (x[0], -x[1]))
a_list_1 = [aa[0] for aa in a_list]
a_list_2 = [aa[1] for aa in a_list]
ans = 0
for i in range(m):
    k = bisect.bisect_right(a_list_1, m - i) - 1
    if k >= 0:
        l = len(a_list_2) - list(reversed(a_list_2)).index(max(a_list_2[:k + 1])) - 1
        if l < len(a_list_2):
            if a_list_1[l] <= m - i:
                ans += a_list_2[l]
                del a_list_1[l], a_list_2[l]
print(ans)

Submission status: Wrong Answer

Solution code:
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
            now += 1
        if now == m:
            break
    return earn


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

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 ab in AB:
    if ab[0] <= M:
        ans += ab[1]
        M -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def d_summer_vacation(N, M, Conditions):
    from collections import defaultdict, deque
    from heapq import heappushpop, heappush
    conds = defaultdict(list)
    for a, b in Conditions:
        conds[a].append(b)
    conds = sorted(conds.items(), key=lambda x: -x[0])

    ans = []
    days_left = M
    for day, benefit in conds:
        benefit.sort(reverse=True)
        candidate = deque(benefit[:days_left - day + 1])
        if len(ans) + len(candidate) <= M:
            for x in candidate:
                heappush(ans, x)
        else:
            while len(ans) < M:
                heappush(ans, candidate.popleft())
            for x in candidate:
                heappushpop(ans, x)
        days_left -= 1
    return sum(ans)

N, M = [int(i) for i in input().split()]
Conditions = [[int(i) for i in input().split()] for j in range(N)]
print(d_summer_vacation(N, M, Conditions))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

N, M = map(int, input().split())
w = sorted([tuple(map(int, input().split())) for _ in range(N)])
u = sorted(w[:], key=lambda x: x[1], reverse=True)
days = [x[0] for x in w]
ans = 0
for i in range(M):
    c = bisect_right(days, M-i) - 1
    d = bisect_right(days, u[0][0]) - 1
    if c < 0:
        break
    if w[c][1] >= w[d][1]:
        ans += w[c][1]
        del w[c]
        del days[c]
    else:
        ans += w[d][1]
        del w[d]
        del days[d]
        del u[0]

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n, m = map(int,input().split( ))

line=[list(map(int,input().split( ))) for i in range(n)]
line.sort(key=itemgetter(1, 0), reverse=True)

# print(line)

res=m   #残り日数
c=0
flag=True
while res>0 and line!=[]:
    if line[0][0] <= res:
        c+=line[0][1]
        flag=True   #働いて1日消費
        line.pop(0)
    else:
        line.pop(0)
        flag=False   #働かない
    if flag:
        res-=1

print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
parttime = []

for i in range(N):
	a, b = map(int, input().split())
	parttime.append((-b, -a))
	
parttime.sort()
index = 0
ans = 0

for day in range(M + 1):
	flag = 0
	
	while index < N:
		if (-parttime[index][1] + day) <= M:
			ans -= parttime[index][0]
			flag = 1
			#print(parttime[index])

		index += 1
		
		if flag == 1:
			break
			
print(ans)
#print(parttime)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
# AB = [ab for ab in AB if ab[0] <= M]
AB.sort(key=lambda ab: (-ab[1], -ab[0]))

ans = 0
i = 0
for d in range(1, M+1):
    while i < N:
        if AB[i][0] > M - d + 1:
            i += 1
        else:
            break
    else:
        break
    ans += AB[i][1]
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
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)
# for i in range(len(bit)):
#     print(i, bit.sum(i))
# print(ans)

AB.sort(key=lambda ab: (ab[0], -ab[1]))
heap = []
idx = AB[0][0]
ans = 0
abi = 0
while idx <= M and (heap or abi < N):
    if abi < N:
        if AB[abi][0] <= idx:
            while abi < N and AB[abi][0] <= idx:
                a, b = AB[abi]
                heapq.heappush(heap, (-b, a))
                abi += 1
        else:
            idx += 1

    if heap:
        b, a = heapq.heappop(heap)
        ans += -b
        idx += 1

print(ans)

Submission status: Wrong Answer

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

works =[None] * n
for i in range(n):
    day, money = map(int, input().split())
    works[i] = [money, day]

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


#print(sorted_works)
now = 0
ans = 0
for i in range(n):
    if now + sorted_works[i][1] > m:
        continue
    else:
        ans += sorted_works[i][0]
        now += 1

    if now == m:
        break

print(ans)