Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
jobs = dict()

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [b]
    else:
        jobs[a].append(b)
# print(jobs)
days = []
money_list = [0]
for i in range(1, m+1):
    # print('days', days)
    if i in jobs.keys():
        money_list.extend(jobs[i])
    # print(money_list)
    max_money = money_list.pop(money_list.index(max(money_list)))
    days.append(max_money)
    if max_money == 0:
        money_list.append(0)
print(sum(days))


Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
jobs = dict()

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [b]
    else:
        jobs[a].append(b)

# print(jobs)

days = []
money_list = [0]
for i in range(1, m+1):
    # print('days', days)
    if i in jobs.keys():
        money_list.extend(jobs[i])
    # print(money_list)
    days.append(max(money_list))
    if max(money_list) != 0:
        money_list.remove(max(money_list))

print(sum(days))


Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
jobs = dict()

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [b]
    else:
        jobs[a].append(b)

print(jobs)

days = []
money_list = [0]
for i in range(1, m+1):
    # print('days', days)
    if i in jobs.keys():
        money_list.extend(jobs[i])
    # print(money_list)
    days.append(max(money_list))
    money_list.remove(max(money_list))

print(sum(days))


Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
jobs = []

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

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

days = [0 for i in range(m)]
for i in range(n):
    # print(jobs_sorted[i])
    after = jobs_sorted[i][0]
    money = jobs_sorted[i][1]
    if after <= m:
        for j in range(m - after, -1, -1):
            if days[j] < money:
                days.insert(j + 1, money)
                del days[0]
                break
    # print(days)

print(sum(days))

Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
jobs = []

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

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

days = [0 for i in range(m)]
for i in range(n):
    # print(jobs_sorted[i])
    if jobs_sorted[i][0] <= m:
        for j in range(m - jobs_sorted[i][0], -1, -1):
            if days[j] < jobs_sorted[i][1]:
                days.insert(j + 1, jobs_sorted[i][1])
                del days[0]
                break
    # print(days)

print(sum(days))

Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
jobs = []

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

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

days = [0 for i in range(m + 1)]
for i in range(n):
    # print(jobs_sorted[i])
    if jobs_sorted[i][0] <= m:
        for j in range(m - jobs_sorted[i][0], -1, -1):
            if days[j] < jobs_sorted[i][1]:
                for k in range(0, j):
                    if days[k+1] != 0:
                        days[k] = days[k+1]
                days[j] = jobs_sorted[i][1]
                break
    # print(days)

print(sum(days))

Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

today = 0

after = []
money = []

for i in range(n):
    a, b = map(int, input().split())
    after.append(a)
    money.append(b)

sum_money = 0
for day in range(m, -1, -1):
    # print('day',day)
    # print('after', after)
    maxi = [-1, 0]
    for i, x in enumerate(after):
        if x <= (m - day):
            if maxi[1] < money[i]:
                maxi = [i, money[i]]
    if maxi[0] == -1:
        continue
    # print('maxi', maxi)
    del after[maxi[0]]
    del money[maxi[0]]
    sum_money += maxi[1]

print(sum_money)


Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

today = 0

after = []
money = []

for i in range(n):
    a, b = map(int, input().split())
    after.append(a)
    money.append(b)

sum_money = 0
for day in range(m, -1, -1):
    # print('day',day)
    # print('after', after)
    candidates = [[i, money[i]] for i, x in enumerate(after) if x <= (m - day)]
    # print(candidates)
    if candidates:
        maxi = [-1, 0]
        for cand in candidates:
            if maxi[1] < cand[1]:
                maxi = cand
        # print('maxi', maxi)
        del after[maxi[0]]
        del money[maxi[0]]
        sum_money += maxi[1]

print(sum_money)


Fixed submission:
import heapq

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)