Buggy python submission (verdict: Time Limit Exceeded):

class Job(object):
    def __init__(self, day, reward):
        self.day = day
        self.reward = reward
        self.is_used = False


class MyJobs(object):
    def __init__(self, num_elements_in_array):
        self.heapm = {}

    def append(self, priority, value):
        if not priority in self.heapm.keys():
            self.heapm[priority] = []
        self.heapm[priority].append(value)

    def get_best(self, priority):
        day = -1
        reward = -1

        for i in range(priority + 1):
            if not (i in self.heapm.keys()):
                continue
            for j in range(len(self.heapm[i])):
                if self.heapm[i][j].is_used:
                    continue
                cur = self.heapm[i][j].reward
                if not (0 > day):
                    best = self.heapm[day][reward].reward
                if (0 > day) or (cur > best):
                    day = i
                    reward = j
        if (0 > day):
            return 0
        self.heapm[day][reward].is_used = True
        return self.heapm[day][reward].reward


(n, m) = map(int, input().split())
jobs = MyJobs(m)
for _ in range(n):
    (a, b) = map(int, input().split())
    jobs.append(a - 1, Job(a - 1, b))

sum = 0
for i in range(m):
    sum += jobs.get_best(i)
print(sum)


Fixed submission:
import heapq

(n, m) = map(int, input().split())
jobs = {}
for _ in range(n):
    (a, b) = map(int, input().split())
    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)

Buggy python submission (verdict: Time Limit Exceeded):

class Job(object):
    def __init__(self, day, reward):
        self.day = day
        self.reward = reward
        self.is_used = False


class MyJobs(object):
    def __init__(self, num_elements_in_array):
        self.heap = [[] for _ in range(100000)]

    def append(self, priority, value):
        self.heap[priority].append(value)

    def get_best(self, priority):
        day = -1
        reward = -1
        for i in range(priority + 1):
            for j in range(len(self.heap[i])):
                if self.heap[i][j].is_used:
                    continue
                cur = self.heap[i][j].reward
                if not (0 > day):
                    best = self.heap[day][reward].reward
                if (0 > day) or (cur > best):
                    day = i
                    reward = j
        if (0 > day):
            return 0
        self.heap[day][reward].is_used = True
        return self.heap[day][reward].reward


(n, m) = map(int, input().split())
jobs = MyJobs(m)
for _ in range(n):
    (a, b) = map(int, input().split())
    jobs.append(a - 1, Job(a - 1, b))

sum = 0
for i in range(m):
    sum += jobs.get_best(i)
print(sum)


Fixed submission:
import heapq

(n, m) = map(int, input().split())
jobs = {}
for _ in range(n):
    (a, b) = map(int, input().split())
    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)

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


class Work(object):
    def __init__(self, a, b):
        self.a = a
        self.b = b
        self.is_used = False


(n, m) = map(int, input().split())
works = []
for _ in range(n):
    (a, b) = map(int, input().split())
    works.append(Work(a, b))
sorted_works = sorted(works, key=lambda x: x.a)

sum = 0
for i in range(1, m + 1):
    options = []
    for j, work in enumerate(sorted_works):
        if work.a > i:
            break
        if work.is_used:
            continue
        heapq.heappush(options, (-work.b, j))
    if 0 == len(options):
        continue
    target = heapq.heappop(options)
    sum += -1 * target[0]
    sorted_works[target[1]].is_used = True
print(sum)


Fixed submission:
import heapq

(n, m) = map(int, input().split())
jobs = {}
for _ in range(n):
    (a, b) = map(int, input().split())
    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)

Buggy python submission (verdict: Time Limit Exceeded):
class work(object):
    def __init__(self, nums):
        self.a = nums[0]
        self.b = nums[1]
        self.is_used = False

    def __repr__(self):
        return "({}, {})".format(self.a, self.b)

    def __lt__(self, other):
        if self.a == other.a:
            return self.b > other.b
        return self.a < other.a


(n, m) = map(int, input().split())
works = []
for _ in range(n):
    works.append(work(list(map(int, input().split()))))
sorted_works = sorted(works)

sum = 0
for i in range(1, m + 1):
    index = 0
    for j, w in enumerate(sorted_works):
        if i < w.a:
            break
        index += 1
    if 0 == index:
        continue
    max_index = 0
    max_reward = 0
    for j in range(index):
        if (not sorted_works[j].is_used) and (max_reward < sorted_works[j].b):
            max_index = j
            max_reward = sorted_works[j].b
    sum += max_reward
    sorted_works[max_index].is_used = True

print(sum)


Fixed submission:
import heapq

(n, m) = map(int, input().split())
jobs = {}
for _ in range(n):
    (a, b) = map(int, input().split())
    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)

Buggy python submission (verdict: Time Limit Exceeded):
class work(object):
    def __init__(self, nums):
        self.a = nums[0]
        self.b = nums[1]

    def __repr__(self):
        return "({}, {})".format(self.a, self.b)

    def __lt__(self, other):
        if self.a == other.a:
            return self.b > other.b
        return self.a < other.a


(n, m) = map(int, input().split())
works = []
for _ in range(n):
    works.append(work(list(map(int, input().split()))))
sorted_works = sorted(works)

sum = 0
for i in range(1, m + 1):
    index = 0
    for j, w in enumerate(sorted_works):
        if i < w.a:
            break
        index += 1
    if 0 == index:
        continue
    target_works = sorted_works[:index]
    best_work = max(enumerate(target_works), key=lambda x: x[1].b)
    sum += best_work[1].b
    del sorted_works[best_work[0]]

print(sum)


Fixed submission:
import heapq

(n, m) = map(int, input().split())
jobs = {}
for _ in range(n):
    (a, b) = map(int, input().split())
    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)