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:
#!/usr/bin/env python3
import sys, math, fractions, itertools, heapq


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


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

if __name__ == '__main__':
    main()

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)

ans = 0
day = 0
for a, b in AB:
    if day == N:
        break
    if a + day <= M:
        ans += b
        day += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split(' '))
    works = [list(map(int, input().split(' '))) for _ in range(n)]
    works = sorted(works, key=lambda l: l[0], reverse=True)
    earned = 0
    for t in range(m, 0, -1):
        works = list(filter(lambda w: w[0] <= t, works))
        if works:
            earned += max(works, key=lambda l: l[1])[1]
            del works[works.index(max(works, key=lambda l: l[1]))]
    print(earned)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

total = 0
for i in range(m):
  max=0
  max_j=0
  max_day=0
  #残り日数 m-iより支払い日が短いもので最大の値をとる
  for j in range(len(w)):
    if w[j][0] <= m-i and w[j][1] > max: # 最大値が来たときは置き換え
      max = w[j][1]
      max_j=j
      max_day=w[j][0]
    elif w[j][0] <= m-i and w[j][1] == max:#最大値と同じ値のときは、日数が長いものを採用
      if w[j][0] > max_day:
        max = w[j][1]
        max_j=j
        max_day=w[j][0]
        
  total = total+max
  if(len(w)>0):
    w.pop(max_j)

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dic = {}
for m in range(1,M+1):
    dic.setdefault(m,[])
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    if A <= M: dic.setdefault(A, []).append(B)

buf = []
cnt = 0
for m in dic.keys():#sorted(dic.keys()):
    buf.extend(dic[m][:M-m+1])
    if buf:
        buf = sorted(buf,reverse=True)
        cnt += buf.pop(0)
print(cnt)

Submission status: Wrong Answer

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

dic = {}
for m in range(1,M+1):
    dic.setdefault(m,[])
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    if A <= M: dic.setdefault(A, []).append(B)

buf = []
cnt = 0
for m in dic.keys():#sorted(dic.keys()):
    buf.extend(sorted(dic[m],reverse=True)[:M-m+1])
    if buf:
        buf = sorted(buf)
        cnt += buf.pop(0)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dic = {}
for m in range(1,M+1):
    dic.setdefault(m,[])
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    if A <= M: dic.setdefault(A, []).append(B)

buf = []
cnt = 0
for m in range(1,M+1):#sorted(dic.keys()):
    buf.extend(dic[m])
    if buf:
        cnt += sorted(buf).pop(0)
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

for index in range(int(len(hiyatoi))):
  hiyatoi[index].append(hiyatoi[index][1]/hiyatoi[index][0])

for index in range(int(len(hiyatoi))):
  maxvalue_index = np.array(hiyatoi).argmax(axis = 0)[2]
  salary += int(hiyatoi[maxvalue_index][2])
  hiyatoi[maxvalue_index] = [0,0,0]

print(salary)

Submission status: Wrong Answer

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

dic = {}
for m in range(1,M+1):
    dic.setdefault(m,[])
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    if A <= M: dic.setdefault(A, []).append(B)

buf = []
cnt = 0
for m in range(1,M+1):#sorted(dic.keys()):
    buf.extend(sorted(dic[m],reverse=True)[:M-m+1])
    if buf:cnt += buf.pop(0)
print(cnt)

Submission status: Wrong Answer

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

dic = {}
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    if A <= M: dic.setdefault(A, []).append(B)

buf = []
cnt = 0
for m in sorted(dic.keys()):
    buf.extend(sorted(dic[m],reverse=True)[:M-m+1])
    cnt += buf.pop(0)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
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((a, b))
	
parttime.sort()
index = 0
ans = 0
myheap = []

for day in range(M, -1, -1):
	for i in range(index, N):
		if (parttime[i][0] + day) <= M:
			heapq.heappush(myheap, -parttime[i][1])		
		else:
			index = i
			break
			
	if myheap:
		ans -= heapq.heappop(myheap)
		
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
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((a, b))
	
parttime.sort()
index = 0
ans = 0
myheap = []

for day in range(M - 1, -1, -1):
	for i in range(index, N):
		if (parttime[i][0] + day) <= M:
			heapq.heappush(myheap, -parttime[i][1])		
		else:
			index = i
			break
			
	if myheap:
		ans -= heapq.heappop(myheap)
		
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

for index in range(int(len(hiyatoi))):
  hiyatoi[index][0] += index
  if hiyatoi[index][0] <= m:
  	count += hiyatoi[index][1]

print(count)

Submission status: Wrong Answer

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

for i in range(N):
	a, b = map(int, input().split())
	jobs.append((a, b))
	
jobs.sort()
index = 0
ans = 0
myheap = []

for day in range(M - 1, -1, -1):
	for i in range(index, N):
		if (day + jobs[i][0]) < (M + 1):
			heapq.heappush(myheap, -jobs[i][1])
		else:
			index = i
			break
			
	if len(myheap) > 0:
		ans -= heapq.heappop(myheap)
		
print(ans)

Submission status: Wrong Answer

Solution code:
import  heapq

N, M = map(int, input().split())
data = [[int(x) for x in input().split()] for i in range(N)]
data.sort(reverse=True, key=lambda x: (-x[0], x[1]))

day = M
reward = 0

# d日前
q = []
i = 0
for d in range(1, M + 1):
    print(d)
    for t in range(i, N):
        if data[t][0] > d:
            break
        i += 1
        heapq.heappush(q, -1 * data[t][1])
    if q:
        reward += heapq.heappop(q)

print(-1 * reward)

Submission status: Wrong Answer

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

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

sa = sorted(ab,key=(lambda x : x[1]), reverse=True)
ans=0
for today in range(m):
  sa = [i for i in sa if i[0] + today <= m]
  if sa != []:
    ans += sa[0][1]
    del sa[0]
print(ans)

Submission status: Wrong Answer

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

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

sa = sorted(ab,key=(lambda x : x[1]), reverse=True)
print(sa)
ans=0
for today in range(m):
  sa = [i for i in sa if i[0] + today <= m]
  if sa != []:
    ans += sa[0][1]
    del sa[0]
print(ans)

Submission status: Wrong Answer

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

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

sa = sorted(ab,key=(lambda x : x[1]), reverse=True)
ans=0
for today in range(m):
  fsa = [i for i in sa if i[0] + today < m]
  while fsa != []:
    ans += fsa[0][1]
  
    del fsa[0]
print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from operator import itemgetter

args = input().split()

# バイトの件数
N = int(args[0])
# ゴールの日
M = int(args[1])

work_list = []
for i in range(N):
    work = input().split()
    work_list.append(work)
#    if int(work[0]) > M:
#        pass
#    else:
#        work_list.append(work)

work_list = sorted(work_list, key=itemgetter(1))
work_list.reverse()

#print(work_list)
current = 0
money = 0
for work in work_list:
    if current + int(work[0]) <= M:
#        print(work)
        money += int(work[1])
        current += 1

#    if current > M:
#        break
print(money)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
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((a, b))
	
parttime.sort()
index = 0
ans = 0
myheap = []

for day in range(M - 1, -1, -1):
	for i in range(index, N):
		'''
		print(day)
		print(parttime[i][0])
		print()
		'''
		if (parttime[i][0] + day) <= M:
			#print('push!')
			heapq.heappush(myheap, -parttime[i][1])
		
		else:
			index = i
			break
			
	if len(myheap) > 0:
		ans -= heapq.heappop(myheap)
		
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
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((a, b))
	
parttime.sort()
index = 0
ans = 0
myheap = []

for day in range(M - 1, -1, -1):
	for i in range(index, N):
		'''
		print(day)
		print(parttime[i][0])
		print()
		'''
		if (parttime[i][0] + day) <= M:
			#print('push!')
			heapq.heappush(myheap, -parttime[i][1])
		
		else:
			index = i
			break
			
	if len(myheap) > 0:
		print(-myheap[0])
		ans -= heapq.heappop(myheap)
		
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = input().split()
N, M = int(N), int(M)
J = [[int(x) for x in input().split()] for _ in range(N)]

#J = sorted(J, key=lambda x: x[0], reverse=True)

#print(J)
reward = 0
for t in range(len(J)):
  best_today = (0, 0)
  candidates = []
  for i, j in enumerate(J) :
    a, b = j
    #print(M - t, a)
    if M - t == a and best_today[1] < b:
      best_today = (i, b)
    elif M - t > a:
      candidates.append((i, b))
  max_cand = (-1, -1)
  for c in candidates:
    if max_cand[1] < c[1]:
      max_cand = c
  #print(best_today, max_cand)
  if best_today[1] >= max_cand[1]:
    reward += best_today[1]
    del J[best_today[0]]
  else:
    reward += max_cand[1]
    del J[max_cand[0]]
  #print(reward)
    
print(reward)

Submission status: Wrong Answer

Solution code:
'''
rows , days = map(int,input().split())
total = 0
arr2 = [[] for _ in range(days)]

for i in range(rows):
    day , r = list(map(int,input().split()))
    if day <= days:
        arr2[day].append(r)

print(arr2)
'''

#標準入力受け取り
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)

print(jobs)
#解法
rewards = 0
li = []
for i in range(M):
    #候補をリストに追加(給料が間に合うもの仕事が一日ごとに増える)
    li.extend(jobs[i])
    if len(li) >0:
        #最大値を求める(給料が高いバイトをしたい)
        reward = max(li)
        rewards += reward
        #使った値は取り除く(同じバイトはNGのため)
        li.remove(reward)

print(rewards)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,m = map(int,input().split())
	ab_sorted = [list(map(int,input().split())) for _ in range(n)]
	#unti = sorted(ab, key = lambda x:x[0])
	#ab_sorted = sorted(unti, key =  lambda x:x[1])
	ans = 0
	for i  in range(1,m+1):
		for j in reversed(ab_sorted):
			if(j[0] <= i):
				ans += j[1]
				ab_sorted.remove(j)
				break
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

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

ans = 0
for job in jobs:
    day, reward = job
    if day <= m:
        ans += reward
        m -= 1

print(ans)

Submission status: Wrong Answer

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

for i in range(m+1):
    #1行後でpopで取り出すので，-1で指定しないといけない
    while jobs and jobs[-1][0] < i+1:
        a,b = jobs.pop()#jobsの一番最後の要素を取り出して削除
        #あとで最大の要素を取り出したいが，heappopは最小の要素を取り出すので-1倍して格納
        heapq.heappush(q,-b)
            
    
    if q:#リストqが空のときはskip
        #heappopで最小の要素を-1倍して取り出すと最大の要素
        sum += -heapq.heappop(q)
print(sum)

Submission status: Wrong Answer

Solution code:
import heapq

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

d = {}
for a,b in ab_list:
    if a in d:
        d[a].append(-b)
    else:
        d[a] = [-b]

b_list = []
heapq.heapify(b_list)
reward = 0
for i in range(1,M+1):
    if i in d:
        b_list = list(heapq.merge(b_list, sorted(d[i])))
    if len(b_list) > 0:
        reward += -(heapq.heappop(b_list))

print(reward)

Submission status: Wrong Answer

Solution code:
# Python code to sort the tuples using second element 
# of sublist Inplace way to sort using sort() 
def Sort(sub_li): 

	# reverse = None (Sorts in Ascending order) 
	# key is set to sort using second element of 
	# sublist lambda has been used 
	sub_li.sort(key = lambda x: x[1]) 
	return sub_li 

p=input().rstrip().split(' ')
l=[]
for i in range(0,int(p[0])):
    u=input().rstrip().split(' ')
    l.append(u)
l=Sort(l)
l.reverse();
SS=0;
AA=0;
for i in range(0,len(l)):
    A=int(l[i][0])+(AA)
    if A<=int(p[1]):
        SS+=int(l[i][1])
        AA+=1;
print(SS)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB = [[0,0]]*N
for n in range(N):
    AB[n] = list(map(int,input().split()))
work_schedule = [0]*M
sorted_AB = sorted(AB,key=lambda x:(-x[1],x[0]))
for work in sorted_AB:
    cnt = 0
    while True:
        if work[0]-1+cnt >= M:
            break
        elif work_schedule[work[0]-1+cnt] == 0:
            work_schedule[work[0]-1+cnt]  = work[1]
            break
        elif  work_schedule[work[0]-1+cnt] != 0:
            cnt+=1
sum(work_schedule)

Submission status: Wrong Answer

Solution code:
import heapq
N,M = map(int, input().split())
works = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a not in works:
        works[a] = []
    else:
        works[a].append(b)
rewards = []
reward_sum = 0
for k in range(M+1):
    if k in works:
        for j in works[k]:
            heapq.heappush(rewards, -j)
    if len(rewards) != 0:
        reward_sum -= heapq.heappop(rewards)
print(reward_sum)

Submission status: Wrong Answer

Solution code:
import heapq
#listから複数index削除するやつ
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

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

work.sort() #日付の短い順にsortしておく　これいる？いる！！！！
tank=[] #候補を入れる
res=0 #回答
j=0

for i in range(M+1): #日付を後ろから見ていく
  while j<=N-1 and work[j][0]<=i: #forじゃないのはheapqに入れた分はずっと候補なのでもうみなくていいため
    heapq.heappush(tank,-work[j][1])
    j+=1
  print("tank1:",tank)
  
  if len(tank)==0: #候補がなければ次の日へ
    print("continue.")
    continue

  else: #候補があればもっとも良いのを回答に足す
    res -= heapq.heappop(tank)
    print("res=",res)
    
  print("tank2:",tank)
    
print(res)

Submission status: Wrong Answer

Solution code:
n,m = (int(i) for i in input().split())
a=[]
b=[]
for i in range(n):
    tmp,tmp2 = (int(i) for i in input().split())
    a.append(tmp)
    b.append(tmp2) 
ans = 0
for i in range(1,m+1):
    maxi = -1
    idx = -1
    flag = False
    for j in range(len(a)):
        if(a[j]<=i and maxi<=b[j]):
            flag=True
            maxi = b[j]
            idx = j

    if(flag):
        ans += maxi
        a.pop(j)
        b.pop(j)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


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

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

day = M
Ans = 0
for W in Wlist:
    if day <= 0:
        break
    if W[0] <= day:
        Ans += W[1]
    day -= 1
    
print(Ans)

Submission status: Wrong Answer

Solution code:
import heapq
#listから複数index削除するやつ
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

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

work.sort() #日付の短い順にsortしておく　これいる？いる！！！！
tank=[] #候補を入れる
res=0 #回答
indexlist=[] #バイトは重複不可なので決定済の労働をindexで管理

for i in range(M+1): #日付を後ろから見ていく
  work=dellist(work,indexlist)
  for n,item in enumerate(work): #（日付的に働けるかをみて）候補たりうるものを探しheapqに突っ込む
    if item[0]<=i:
      heapq.heappush(tank,-item[1])
      indexlist.append(n)
  #print("tank1:",tank)
  
  if len(tank)==0: #候補がなければ次の日へ
    #print("continue.")
    continue

  else: #候補があればもっとも良いのを回答に足す
    res -= heapq.heappop(tank)
    #print("res=",res)
    
  #print("tank2:",tank)
    
print(res)

Submission status: Wrong Answer

Solution code:
import heapq
import sys

n,m=map(int,input().split())
job=[]
for i in range(n):
    a,b=map(int,input().split())
    job.append([-1*(10**6*b+a),b,a])
heapq.heapify(job)
point=0
for i in range(m):
    if job:
        while(job):
            _,s,t=heapq.heappop(job)
            if i+t<=m:
                point+=s
                break
    else:
        break
print(point)

Submission status: Wrong Answer

Solution code:
import heapq
import sys

n,m=map(int,input().split())
job=[]
for i in range(n):
    a,b=map(int,input().split())
    job.append([-1*(10**5*b+a),b,a])
heapq.heapify(job)
point=0
for i in range(m):
    if job:
        while(job):
            _,s,t=heapq.heappop(job)
            if i+t<=m:
                point+=s
                break
    else:
        break
print(point)

Submission status: Wrong Answer

Solution code:
data = list()
sum = 0
N, M = input().split(" ")
M = int(M)
N = int(N)
for i in range(N):
    A, B = input().split()
    data.append([int(B), int(A)])
data.sort()
while M > 0:
    for i in reversed(range(N)):
        tempB, tempA = data[i]
        if tempA <= M:
            data.pop(i)
            N -= 1
            sum += tempB
            break
    M -= 1
print(sum)

Submission status: Wrong Answer

Solution code:
import heapq

(n, m) = map(int, input().split())
jobs = {}
for _ in range(n):
    (a, b) = map(int, input().split())
    if b > (m + 1):
        continue
    if not a in jobs:
        jobs[a] = []
    jobs[a].append(-b)

heap = []
sum = 0
for i in range(1, m + 1):
    if i in jobs:
        for j in jobs[i]:
            heapq.heappush(heap, j)
    if 0 < len(heap):
        sum -= heapq.heappop(heap)
print(sum)

Submission status: Wrong Answer

Solution code:
import heapq

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

tank = []

n = 10**5
p = []

for i in range(n):
    p.append([1,1])
p.sort()

q = 0
res = 0
"""
for i in range(m+1):
    while q <= n-1 and p[q][0] <= i:
        heapq.heappush(tank,-p[q][1])
        q += 1
    
    if len(tank) == 0:
        continue
    else:
        res -= heapq.heappop(tank)
    #print(res)
"""
print(res)

Submission status: Wrong Answer

Solution code:
import heapq

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

rewards_list_vs_days = [[] for _ in range(M+1)]
for _ in range(N):
    days,reward = list(map(int, input().split()))
    if days <= M:
        rewards_list_vs_days[days].append(reward)

print(rewards_list_vs_days)

minus_rewards_of_available_jobs = []

total_reward = 0

for day in reversed(list(range(M))):
    rest_days = M-day
    for reward in rewards_list_vs_days[rest_days]:
        heapq.heappush(minus_rewards_of_available_jobs, -reward)
    if len(minus_rewards_of_available_jobs) > 0:
        max_reward = - heapq.heappop(minus_rewards_of_available_jobs)
        total_reward += max_reward
    
print(total_reward)

Submission status: Wrong Answer

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

n,m=map(int,input().split())
l=[[0,0] for _ in range(n)]
for i in range(n):
        l[i][1],l[i][0]=map(int,input().split())
l.sort()
l=l[::-1]
ans=0
for k in range(1,m+1):
        for j in range(len(l)):
                if l[j][1]<=k:
                        ans+=l[j][0]
                        del l[j]
                        break
print(l,ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from operator import itemgetter

args = input().split()

# バイトの件数
N = int(args[0])
# ゴールの日
M = int(args[1])

work_list = []
for i in range(N):
    work = input().split()
    work_list.append(work)
#    if int(work[0]) > M:
#        pass
#    else:
#        work_list.append(work)

work_list = sorted(work_list, key=itemgetter(1))
work_list.reverse()

current = 0
money = 0
for work in work_list:
    if current + int(work[0]) <= M:
        money += int(work[1])
        current += 1

    if current > M:
        break
print(money)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from operator import itemgetter

args = input().split()

# バイトの件数
N = int(args[0])
# ゴールの日
M = int(args[1])

work_list = []
for i in range(N):
    work = input().split()
    work_list.append(work)
#    if int(work[0]) > M:
#        pass
#    else:
#        work_list.append(work)

work_list = sorted(work_list, key=itemgetter(1))
work_list.reverse()

current = 0
money = 0
for work in work_list:
    if current + int(work[0]) <= M:
        money += int(work[1])
        current += 1

    if current >= M:
        break
print(money)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from operator import itemgetter

args = input().split()

# バイトの件数
N = int(args[0])
# ゴールの日
M = int(args[1])

work_list = []
for i in range(N):
    work = input().split()
    if int(work[0]) > M:
        pass
    else:
        work_list.append(work)

work_list = sorted(work_list, key=itemgetter(1))
work_list.reverse()

current = 0
money = 0
for work in work_list:
    if current + int(work[0]) <= M:
        money += int(work[1])
        current += 1

    if current >= M:
        break
print(money)

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 in AB:
        AB[a].append(b)
    else:
        AB[a] = [b]

count = 0
current = []
day_list = list(AB.keys())
day_list.append(M + 1)
day_list.sort()

previous_day = day_list[0]
for day in day_list:

    span = day - previous_day
    #print(current[:span])
    #print(current[span:])
    count += sum(current[:span])
    current = current[span:]

    # add
    if day in AB:
        current.extend(AB[day])
        current.sort(reverse=True)
    previous_day = day



print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1] = map(int, input().split())
a.sort(reverse=True, key=lambda x:x[1])
a.sort(reverse=True, key=lambda x:x[0])

i = 0
b = 0
ans = 0
while(i == n or m < b):
  if m - b >= a[i][0]:
    ans += a[i][1] 
    b += 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1] = map(int, input().split())
a.sort(reverse=True, key=lambda x:x[1])
a.sort(reverse=True, key=lambda x:x[0])

i = 0
b = 0
ans = 0
while(i == n or m < b):
  if m >= b + a[i][0]:
    ans += a[i][1] 
    b += 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1] = map(int, input().split())
a.sort(reverse=True, key=lambda x:x[1])
a.sort(reverse=True, key=lambda x:x[0])

i = 0
b = 0
ans = 0
while(i == n or m < 1):
  if m >= b + a[i][0]:
    ans += a[i][1] 
    b += a[i][0]
    m -= 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1] = map(int, input().split())
a.sort(reverse=True, key=lambda x:x[1])

i = 0
ans = 0
while(i == n or m < 0):
  if m >= a[i][0]:
    ans += a[i][1]
    m -= 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1]  = map(int, input().split())
  a[i].append(a[i][1]/a[i][0])
a.sort(reverse=True, key=lambda x:x[1])

i = 0
ans = 0
while(i == n or m < 1):
  ans += a[i][1]
  m -= 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# M日後に最大の値
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(1, M+1):
    temp = 0
    index = -1
    for j in range(len(Data)):
        if (Data[j][0] <= i) and (temp < Data[j][1]):
            temp = Data[j][1]
            index = j
    if index != -1:
        print(index)
        ans += temp
        Data[index][1] = -1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1]  = map(int, input().split())
  a[i].append(a[i][1]/a[i][0])
a.sort(reverse=True, key=lambda x:x[1])

i = 0
ans = 0
while(i == n or m < 1):
  if m >= a[i][0]:
    ans += a[i][1]
    m -= 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1]  = map(int, input().split())
  a[i].append(a[i][1]/a[i][0])
a.sort(reverse=True, key=lambda x:x[1])

i = 0
ans = 0
while(i == n or m < 1):
  if m >= a[i][0]:
    ans = a[i][1]
    m -= 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1]  = map(int, input().split())
  a[i].append(a[i][1]/a[i][0])
a.sort(reverse=True, key=lambda x:x[2])

i = 0
ans = 0
while(i == n or m < 1):
  if m >= a[i][0]:
    ans = a[i][1]
    m -= a[i][0]
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1]  = map(int, input().split())
  a[i].append(a[i][1]/a[i][0])
a.sort(key=lambda x:x[2])

i = 0
ans = 0
while(i == n or m < 1):
  if m >= a[i][0]:
    ans = a[i][1]
    m -= a[i][0]
  i += 1
print(ans)