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:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            cand += work[i]
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def p_d():
    n, m = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    sorted(ab)
    ans = 0

    for i in range(1, m + 1):
        idx = -1
        max_value = -1
        for j in range(len(ab)):
            if ab[j][0] <= m:
                if max_value <= ab[j][1]:
                    max_value = ab[j][1]
                    idx = j
            else:
                break

        if idx != -1:
            ans += max_value
            ab.pop(idx)

    print(ans)


if __name__ == '__main__':
    p_d()

Submission status: Wrong Answer

Solution code:
#40分じゃ無理だったよ...400点問題余裕になったらそのときに解いてくれ、
#解説ACすらできなかったけど、よろしく。2019/8/10 23:18

#a=入力用。a[0]がN(バイトの個数)で、a[1]がM(日数)。
#b=受注できるバイトのリスト。
#c=その日受注して間に合うバイトのリスト。
#d=報酬の最大値。出力用。
#e=M日後までの残り日数。

a,b,d=list(map(int,input().split())),[],0 #入力・定義
n,m=a[0],a[1]
for i in range(n):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x:(x[0],x[1])) #受注期限でソートしておく
for i in range(m): #すべての日付について
    c,e=[],m-i #c,eの定義
    for j in range(len(b)): #期限までに金をもらえるバイトをcにコピー
        if e>=b[j][0]: 
            c.append(b[j])
    c=sorted(c,key=lambda x:x[1]) #報酬でソートしておく
    if len(c)<1: #バイトが一つもなかったら終わり
        break
    else:
        d+=c[-1][1] #最大報酬を足す
        b.remove(c[-1]) #請けたバイトは消す
print(d) #報酬を出力

Submission status: Wrong Answer

Solution code:
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_map = {}
each_days_mapsorted_list = []
for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    if a > M:
        break 
    if a in each_days_map.keys():
        for idx in range(len(each_days_map[a])):
            if b > each_days_map[a][idx]:
                each_days_map[a].insert(idx,b)
                if len(each_days_map[a]) > (M - a + 1):
                    each_days_map[a].pop()
                break
        if M > len(each_days_map[a]) and (M - a + 1) > len(each_days_map[a]):
            each_days_map[a].append(b)
    else:
        each_days_map[a] = [b]

fixed_max_list = [0]
for max_list in each_days_map.values():
    for num in max_list:
        list_len = len(fixed_max_list)
        insert_flag = True
        for idx in range(list_len):
            if num > fixed_max_list[idx]:
                fixed_max_list.insert(idx,num)
                insert_flag = False
                if len(fixed_max_list) >= M:
                    fixed_max_list.pop()
                break
        if M > len(fixed_max_list) and insert_flag:
            fixed_max_list.append(b)
print(sum(fixed_max_list))

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

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: -x[1])
cnt, ans = 0, 0
bit = BIT(M)
for a, b in ab:
    # print([bit.sum(i) for i in range(1, M+1)])
    if M-a >= 0 and bit.sum(M-a+1) <= M-a:
        ans += b
        bit.add(M-a+1, 1)
        cnt += 1
        if cnt == M:
            break
# print()
# print([bit.sum(i) for i in range(1, M+1)])
print(ans)

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.insert(idx, d[l[key[-1]+1]][1])
                key.insert(idx, key[-1])
                l[key[-1]] += 1
            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:
import heapq
N, M = map(int, input().split())

q = []
for i in range(N):
    A, B = map(int, input().split())
    heapq.heappush(q, (A, -B))

ans = 0
a, b = heapq.heappop(q)
q2 = []
for j in range(M):
    while a <= j+1 and q:
        heapq.heappush(q2, (b, a))
        a, b = heapq.heappop(q)
    if q2:
        tmp, _ = heapq.heappop(q2)
        ans -= tmp
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None
N, M =LI()
AB = []
for i in range(N):
    AB.append(LI())
#  AB.sort(key=lambda x: x[0])
#  perr(AB)
AB_dict = {}
for ab in AB:
    if ab[0] not in AB_dict.keys():
        AB_dict[ab[0]] = [ab[1]]
    else:
        AB_dict[ab[0]].append(ab[1])
for k in AB_dict.keys():
    AB_dict[k].sort()
perr(AB_dict)
print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.zeros(0)
B = np.zeros(0)

for i in range(N):
    n,m = map(int, input().split()) 
    A = np.append(A, n)
    B = np.append(B, m)  

ans = 0
for i in np.arange(M):
    B = B[A <= M-i]
    A = A[A <= M-i]
    
    if np.size(A) == 0:
        break
    
    k = np.where(B == np.max(B))[0]
                                  
    l = np.argmax(A[k])
    ans += B[k[l]]
                 
    B = np.delete(B, k[l])
    A = np.delete(A, k[l])
                 
print(int(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],-x[1]))
day = 0
cnt = 0
a, b = AB[0]
for i in range(M):
  if a > M:
    break
  if day + a > M:
    break
  cnt += b
  day += 1
  AB.remove([a, b])
  if not AB:
    break
  a, b = max(AB, key = lambda x: (-x[0], x[1]))
print(cnt)

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.insert(idx, d[l[key[-1]+1]][1])
                key.insert(idx, key[-1])
            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:
N, M = map(int, input().split())
case = []
for i in range(N):
    AB = [int(i) for i in input().split()]
    if AB[0] <= M:
        case.append(AB)
    else:
        N -= 1

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

ans = 0
count, shortest = 0, M
for i in range(N):
    if case[i][0] <= M - count or (case[i][0] <= M - (count - 1) and shortest <= M - count):
        shortest = min(shortest, case[i][0])
        count += 1
        ans += case[i][1]

print(ans)

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

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x != 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: -x[1])
cnt, ans = 0, 0
bit = BIT(M+1)
# print(ab)
for a, b in ab:
    # print([bit.sum(i) for i in range(1, M+1)])
    if M-a >= 0 and bit.sum(M-a+1) <= M-a:
        ans += b
        bit.add(M-a+1, 1)
        cnt += 1
        if cnt == M:
            break
# print()
# print([bit.sum(i) for i in range(1, M+1)])
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
case = []
for i in range(N):
    AB = [int(i) for i in input().split()]
    if AB[0] <= M:
        case.append(AB)
    else:
        N -= 1

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

ans = 0
count, shortest = 0, M
for i in range(N):
    if case[i][0] <= M - count or (case[i][0] <= M - (count - 1) and shortest <= M - count):
        shortest = min(shortest, case[i][0])
        count += 1
        ans += case[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
cnt = defaultdict(lambda: defaultdict(lambda: list()))

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

A = []
B = []
AB = []

_ab = [[] for i in range(10**5+1)]
_ab = [[] for i in range(10)]

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



dp = [[] for i in range(10**4+1)]
# dp = [[] for i in range(5)]

AB = sorted(AB, key=lambda x: x[1])
AB = AB[::-1]
b_ab = []
counter = 0

buff = -1
for i in range(N):
    dp[AB[i][1]].append(AB[i])

memo = []
for i in range(10**4+1):
    if len(dp[i]) != 0:
        memo.append(dp[i])


def kansu(el):
    # print(el[0][1])
    return el[0][1]


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

# print(memo)
memo = sorted(memo, key=lambda x: kansu(x), reverse=True)
# print(memo)
AB = []
for i in range(len(memo)):
    for j in range(len(memo[i])):
        AB.append(memo[i][j])

# for el in cnt:
#     cnt[el].sorted()
#     cnt[el] = cnt[el][::-1]

# print(AB)
ans = 0
flag = False
for i in range(M+1, 0, -1):
    c = 0
    # print('c = ' + str(c) + ' ans' + str(ans))
    while True:
        _l = len(AB)
        # print('    {0} {1}'.format(AB, ans))
        if c > _l-1:
            flag = True
            break
        if AB[c][0] < i:
            ans += AB[c][1]
            AB.pop(0)
            break
        else:
            pass
        AB.pop(0)
        c += 1


print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(r)

rewords = 0
heap = []

for i in range(M):
    for reword in jobs[i]:
        heapq.heappush(heap, reword)
    if len(heap) >0:
        r = heapq.heappop(heap)
        print(r)
        rewords += r

print(rewords)

Submission status: Wrong Answer

Solution code:
import heapq as hq
def main():
    n,m = map(int,input().split(' '))
    w = [list(map(int,input().split(' '))) for i in range(n)]
    w=sorted(w)
    ans = 0
    l = []
    tmp = 0
    for i in range(m+1):
        for n,j in enumerate(w[tmp:]):
            if i >= j[0]:
                hq.heappush(l,-j[1])
            else:
                tmp = n
                break
        if len(l) > 0:
            ans -=hq.heappop(l)
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

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

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M+1) :
    for b in AB[a] :
        if len(q) < a + 1 :
            heappush(q, b)
        else :
            heappop(q)
            heappush(q, b)
            
print(sum(q))

Submission status: Wrong Answer

Solution code:
import heapq

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

an = []
for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(an, (b, a))


d = 1
ans = 0
while d <= m:
    for i, job in enumerate(reversed(an)):
        if job[1] <= d:
            ans += job[0]
            del an[len(an) - i - 1]
            break
    d += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    work = [None for _ in range(N)]
    q = []
    heapq.heapify(q)
    for i in range(N):
        a, b = map(int, input().split())
        work[i] = (a, -b)
    
    work.sort()
    ans = 0
    id = 0
    for i in range(M):
        while id < N:
            if work[id][0] <= i + 1:
                q.append((work[id][1], work[id][0]))
                id += 1
            else: break
        
        if q:
            gain, day = heapq.heappop(q)
            ans -= gain

    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

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

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M) :
    for b in AB[a] :
        if len(q) < a + 1 :
            heappush(q, b)
        else :
            heappop(q)
            heappush(q, b)
            
print(sum(q))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
A_B = [[int(i) for i in input().split()] for _ in range(N)]
A_B = [i for i in sorted(A_B, key=lambda x: x[0], reverse=True) if i[0] <= M]
A_B.insert(0, [M, 0])
# print(A_B)

answer = 0
for i in range(M, -1, -1):
  now_list = sorted([j for j in A_B if j[0] == i], reverse=True, key=lambda x: x[1])
  after_list = sorted([j for j in A_B if j[0] < i], reverse=True, key=lambda x: x[1])
  now_list.append([0, 0])
  after_list.append([0, 0])
  if now_list[0][1] >= after_list[0][1] and now_list[0] != [0, 0]:
    answer += now_list[0][1]
    A_B.remove(now_list[0])
  elif after_list[0][1] > now_list[0][1] and after_list[0] != [0, 0]:
    answer += after_list[0][1]
    A_B.remove(after_list[0])
  # print('answer', answer)

print(answer)

Submission status: Wrong Answer

Solution code:
#input = raw_input

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

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

pairs = sorted(pairs, key=lambda elm: -elm[1])
#print(pairs)

finish_day = -1
out = 0

#not_done = [True for _ in range(M)]

counts = [0 for _ in range(M)]
all_sum = 0
for A, B in pairs:
    if A > M:
        continue
    ue_limit = M - (M-A+1) + 1
    ue_sum = sum(counts[M-A+1:])
    hamidashi = max(ue_sum - ue_limit, 0)
    #print("hamidashi", hamidashi)

    cur_limit = M- A + 1 - hamidashi
    sudeni = all_sum - ue_sum
    aki = cur_limit - sudeni
    #print(cur_limit, sudeni, aki, counts, pairs)
    if aki >= 1:
        out += B
        #print(A, B)
        #not_done[i] = False
        #break
    counts[M-A] += 1
    all_sum += 1

print(out)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush, merge

n, m = [int(v) for v in input().split()]
arbs = [tuple(int(v) for v in input().split()) for _ in range(n)]
cands = [[] for _ in range(m)]
for arb in arbs:
    t = m - arb[0]
    if t >= 0:
        heappush(cands[t], -arb[1])
rest = []
total_reward = 0
for cand in reversed(cands):
    rest = list(merge(rest, cand))
    if len(rest) > 0:
        total_reward += -heappop(rest)

print(total_reward)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
T=[]
for i in range(N):
    a,b=map(int, input().split())
    T.append((a,b))
S=sorted(T, key=lambda k:k[1])

day = 0
ans = 0
for i in reversed(range(N)):
    if S[i][0] <= (M - day):
        ans += S[i][1]
        day += 1
        if day >= M:
          break
print(ans)

Submission status: Wrong Answer

Solution code:
input = raw_input

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

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

pairs = sorted(pairs, key=lambda elm: -elm[1])
#print(pairs)

finish_day = -1
out = 0

#not_done = [True for _ in range(M)]

counts = [0 for _ in range(M)]
all_sum = 0
for A, B in pairs:
    if A > M:
        continue
    ue_limit = M - (M-A+1) + 1
    ue_sum = sum(counts[M-A+1:])
    hamidashi = max(ue_sum - ue_limit, 0)
    #print("hamidashi", hamidashi)

    cur_limit = M- A + 1 - hamidashi
    sudeni = all_sum - ue_sum
    aki = cur_limit - sudeni
    #print(cur_limit, sudeni, aki, counts, pairs)
    if aki >= 1:
        out += B
        #print(A, B)
        #not_done[i] = False
        #break
    counts[M-A] += 1
    all_sum += 1

print(out)

Submission status: Wrong Answer

Solution code:
a,b,d=list(map(int,input().split())),[],0
n,m=a[0],a[1]
for i in range(n):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x:(x[0],x[1]))
for i in range(m):
    c=[]
    for j in range(len(b)):
        if m-i>=b[j][0]:
            c.append(b[j])
    c=sorted(c,key=lambda x:x[1])
    if len(c)<1:
        break
    else:
        d+=c[-1][1]
        b.remove(c[-1])
print(d)

Submission status: Wrong Answer

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

for x,y in day.items():
    max_point=max(y)
    day_ans[x]=max_point
    day[x].remove(max_point)
    count -=1

while count!=0:
    for x,y in day.items():
        try:
            max_point=max(y)
            for i in range(x,m+1):
                if day_ans[i]==0:
                    day_ans[i]=max_point
                    day[x].remove(max_point)
                    count -=1
        except:continue
point=0
for x,y in day_ans.items():
    point +=y
print(point)

Submission status: Wrong Answer

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

print(AB)

for n in range(N):
    AB[n][0], AB[n][1] = map(int, input().split())
    AB[n][1] = 0 - AB[n][1]
AB.sort()

earn = 0
for m in range(1, M+1):
    max_earn = 0
    max_i = 0
    for i in range(len(AB)):
        if m < AB[i][0] :
            break
        
        if max_earn > AB[i][1]:
            max_earn = AB[i][1]
            max_i = i


    if max_earn != 0:
        earn += AB[max_i][1]
        AB.pop(max_i)

        

        
print(0-earn)

Submission status: Wrong Answer

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


for i in range(n):
    a,b = map(int, input().split())
    if a <= m:
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]

day = {}
for i in range(1,m+1):
    day[i] = m - i + 1
h = 0
while m > 0:
    if d == {}:
        break
    else:
        mh = max(d)
        if d[mh] == []:
            del d[mh]
        else:
            md = max(d[mh])
            if day[md] > 0:
                day[md] -= 1
                m -= 1
                h += mh
                d[mh].remove(md)
            else:
                d[mh].remove(md)


print(h)

Submission status: Wrong Answer

Solution code:
n , m = list(map(int, input().split(' ')))
s = []
for i in range(n):
    a, b = list(map(int, input().split(' ')))
    s.append([b, a])
s.sort(reverse = True)
i = 0
result = 0
while m > 0:
    if m >= s[i][1]:
        result += s[i][0]
        del s[i]
        m -= 1
        i = 0
    else:
        i += 1
        if i > len(s)-1:
            break
print(result)

Submission status: Wrong Answer

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

inf = float("inf")
prime = 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

"""

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

result = re.fullmatch(pattern, s)

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

#######################################
n,m = map(int, input().split())
a = [0]*n
b = [0]*n
rate = [0]*n

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


done_list =[]
money = 0
for k in range(n):
  for i in range(n):
    rate[i] = b[i] / a[i]
  #print(b)
  #print(a)
  best_idx = np.argmax(rate)
  if best_idx in done_list:
    break
  #print(best_idx)
  money += b[best_idx]
  b[best_idx]=0
  done_list.append(best_idx)
  
  a = [ai+1 if ai== a[best_idx] else ai for ai in a]
  b = [0 if a[j]>m else b[j] for j in range(n)]


print(money)

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

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x != 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

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])
f = [0] * M
cnt, ans = 0, 0
bit = BIT(M+1)
for a, b in ab:
    if M-a >= 0 and bit.sum(M-a+2) <= M-a:
        ans += b
        cnt += 1
        if cnt == M:
            break
        bit.add(M-a+1, 1)
print(ans)

Submission status: Wrong Answer

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

inf = float("inf")
prime = 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

"""

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

result = re.fullmatch(pattern, s)

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

#######################################
n,m = map(int, input().split())
a = [0]*n
b = [0]*n
rate = [0]*n

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


done_list =[]
money = 0
for k in range(n):
  for i in range(n):
    rate[i] = b[i] / a[i]
  #print(b)
  #print(a)
  best_idx = np.argmax(rate)
  if best_idx in done_list:
    break
  print(best_idx)
  money += b[best_idx]
  b[best_idx]=0
  done_list.append(best_idx)
  
  a = [ai+1 if ai== a[best_idx] else ai for ai in a]
  b = [0 if a[j]>m else b[j] for j in range(n)]


print(money)

Submission status: Wrong Answer

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

i = 0
count = 0
while len(ab) != 0:
  p = ab.pop()
  if M - p[0] - i >= 0:
    count += p[1]
    i += 1
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        [a, b] = [int(number) for number in input().split()]
        #money_par_day = b / a
        part_times.append([b, a])
        #part_times.sort(reverse=True)
    part_times = sorted(part_times, key = lambda x: (x[0], x[1]), reverse=True)
    money = 0
    day = 0

    #while day <= M:

    for part_time in part_times:
        [b,a] = part_time
        if a + day <= M:
            day += 1
            money += b
            if day == N:
                break
        else:
            continue
    print(money)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

summation = [[] for i in range(10 ** 5 + 10 ** 4 + 1)]
for i in range(N):
    a, b = map(int, input().split())
    summation[a + b].append((a, b))

lst = []
for i in range(10 ** 5 + 10 ** 4):
    summation[i].sort()
    if summation[i] != []:
        for v in summation[i]:
            lst.append(v)

ans = 0
for i in range(M):
    remain = M - i
    if lst != []:
        while lst != []:
            a, b = lst.pop()
            if a > remain:
                continue
            else:
                ans += b
                break
    else:
        break

print(ans)

Submission status: Wrong Answer

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

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

    if i+day <= m:
        ans += money
print(ans)