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

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

sorted(list_kard, key=lambda x: x[1])
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break
print(sum(list_score))

Fixed submission:
import heapq

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

list_kard.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break

print(sum(list_score))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [ list(map(int,input().split(" "))) for i in range(m)]

list_score_colume = list(set(list_score))

for i in range(len(list_score_colume)):
    k = [list_score.count(list_score_colume[i]), list_score_colume[i]]
    list_kard.append(k)


list_kard = sorted(list_kard, key=lambda x: x[1], reverse=True)


ans = 0
cnt = 0
for i in range(len(list_kard)):
    k = list_kard[i]
    if cnt + k[0] <= n:
        ans += k[0]*k[1]
        cnt += k[0]
    else:
        ans += k[1]*(n-cnt)
        break

print(ans)

Fixed submission:
import heapq

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

list_kard.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break

print(sum(list_score))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [ list(map(int,input().split(" "))) for i in range(m)]

for i in range(m):
    k = list_kard[i]
    l = [k[1]]*k[0]
    list_score.extend(l)

list_score.sort(reverse=True)
print(sum(list_score[:n]))

Fixed submission:
import heapq

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

list_kard.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break

print(sum(list_score))

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

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [ list(map(int,input().split(" "))) for i in range(m)]

heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])

print(sum(list_score))

Fixed submission:
import heapq

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

list_kard.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break

print(sum(list_score))