Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, M = map(int, input().split())
A = list(map(int, input().split()))

A = Counter(A)

for _ in range(M):
    b, c = map(int, input().split())
    A[c] += b

A = list(A.elements())
A.sort(reverse=True)
print(sum(A[:N]))

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))

for i in range(m):
    b, c = map(int, input().split())
    a[c] += b

num = sorted(a.items(), key=lambda x: x[0], reverse=True)
ans = 0

for key, val in num:
    if n > val:
        ans += key * val
        n -= val
    else:
        ans += key * n
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

for i in range(M):
    B, C = map(int, input().split())
    for b in range(B):
        tmp = heapq.heappop(A)
        if tmp < C:
            heapq.heappush(A, C)
        else:
            heapq.heappush(A, tmp)
            continue

print(sum(A))

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))

for i in range(m):
    b, c = map(int, input().split())
    a[c] += b

num = sorted(a.items(), key=lambda x: x[0], reverse=True)
ans = 0

for key, val in num:
    if n > val:
        ans += key * val
        n -= val
    else:
        ans += key * n
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

for i in range(M):
    B, C = map(int, input().split())
    for b in range(B):
        tmp = heapq.heappop(A)
        if tmp < C:
            heapq.heappush(A, C)
        else:
            heapq.heappush(A, tmp)
            continue

print(sum(A))

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))

for i in range(m):
    b, c = map(int, input().split())
    a[c] += b

num = sorted(a.items(), key=lambda x: x[0], reverse=True)
ans = 0

for key, val in num:
    if n > val:
        ans += key * val
        n -= val
    else:
        ans += key * n
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(m)]

mn = min(a)
for i in b:
    if i[1] < mn:
        continue
    a.extend([i[1]] * i[0])

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

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))

for i in range(m):
    b, c = map(int, input().split())
    a[c] += b

num = sorted(a.items(), key=lambda x: x[0], reverse=True)
ans = 0

for key, val in num:
    if n > val:
        ans += key * val
        n -= val
    else:
        ans += key * n
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
a = deque(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(m)]

mn = min(a)
for i in b:
    if i[1] < mn:
        continue
    a = a + deque([i[1]] * i[0])

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

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))

for i in range(m):
    b, c = map(int, input().split())
    a[c] += b

num = sorted(a.items(), key=lambda x: x[0], reverse=True)
ans = 0

for key, val in num:
    if n > val:
        ans += key * val
        n -= val
    else:
        ans += key * n
        break

print(ans)