Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, M = map(int, input().split())
jobs = []
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs.append([day, value])
jobs = sorted(jobs, lambda x: x[0])

ans = 0
hq = []
job_i = 0
for day in range(1, M+1):
    for job in list(jobs[job_i:]):
        if day < job[0]:
            break

        heapq.heappush(hq, - job[1])
        job_i += 1
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
jobs = []
for _ in rangek(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs.append([day, value])

ans = 0
hq = []
for day in range(1, M+1):
    for job in list(jobs):
        if day == job[0]:
            heapq.heappush(hq, - job[1])
            jobs.remove(job)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

ans = 0
hq = []
for day in range(1, M+1):
    for job in list(jobs):
        if day == job[0]:
            heapq.heappush(hq, - job[1])
            jobs.remove(job)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

ans = 0
hq = []
for day in range(1, M+1):
    for job in jobs:
        if day == job[0]:
            heapq.heappush(hq, - job[1])
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
jobs = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for day in range(M, 0, -1):
    best_job = [0, 0]
    for job in jobs:
        if day + job[0] - 1 <= M:
            if best_job[1] <= job[1]:
                best_job = job
    if best_job != [0, 0]:
        jobs.remove(best_job)
        ans += best_job[1]

print(ans)


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
jobs = [list(map(int, input().split())) for _ in range(N)]

def schedule(reward, day, jobs):
    if day > M or not jobs:
        return reward
    else:
        results = []
        for job in jobs:
            if day + job[0] - 1 > M:
                jobs.remove(job)

        if not jobs:
            return reward

        best_jobs = {}
        for job in jobs:
            if job[0] in best_jobs:
                if best_jobs[job[0]][1] < job[1]:
                    best_jobs[job[0]] = job
            else:
                best_jobs[job[0]] = job

        for job in best_jobs.values():
            copied_jobs = list(jobs)
            copied_jobs.remove(job)
            result = schedule(reward + job[1], day + 1, copied_jobs)
            results.append(result)
        return max(results)

print(schedule(0, 1, jobs))


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
jobs = [list(map(int, input().split())) for _ in range(N)]

def schedule(reward, day, jobs):
    if day > M or not jobs:
        return reward
    else:
        results = []
        for job in jobs:
            if day + job[0] - 1 > M:
                jobs.remove(job)

        if not jobs:
            return reward

        for job in jobs:
            copied_jobs = list(jobs)
            copied_jobs.remove(job)
            result = schedule(reward + job[1], day + 1, copied_jobs)
            results.append(result)
        return max(results)

print(schedule(0, 1, jobs))


Fixed submission:
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)