Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int,input().split()))
for _ in range(m):
    b,c = map(int, input().split())
    a += [c]*b
a.sort()
print(sum(a[-n:]))


Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

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

n,m = map(int, input().split())
a = list(map(int,input().split()))
D = []

j = 0
for _ in range(m):
    b,c = map(int, input().split())
    D += [c]*b
D.sort(reverse=True)
for i in range(n):
    if a[i] < D[j]:
        a[i] = D[j]
        j += 1

print(sum(a))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a = list(map(int,input().split()))
D = []
idx = 0
j = 0
for _ in range(m):
    b,c = map(int, input().split())
    D += [c]*b
D.sort(reverse=True)
for i in range(n):
    if a[i] < D[j]:
        a[i] < D[j]
        j += 1

print(sum(a[idx:]))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n,m = map(int, input().split())
a = list(map(int,input().split()))

idx = 0
for _ in range(m):
    b,c = map(int, input().split())
    a += [c]*b
    idx += b
a.sort()
print(sum(a[idx:]))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int,input().split()))
idx = 0
for i in range(m):
    b,c = map(int, input().split())
    a += [c]*b
    idx += b
a.sort()
print(sum(a[idx:]))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = [int(_) for _ in input().split()]
idx = 0
for i in range(m):
    b,c = map(int, input().split())
    a += [c]*b
    idx += b
a.sort()
print(sum(a[idx:]))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = [int(_) for _ in input().split()]
idx = 0
for i in range(m):
    b,c = map(int, input().split())
    a += [c]*b
    idx += b
a.sort()
print(sum(a[idx:]))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)

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

for i in range(m):
    a.sort()
    b,c = map(int, input().split())
    a = [c if j < c else j for j in a[:b]] + a[b:]
    
print(sum(a))

Fixed submission:
from heapq import heappop, heappush


n,m = map(int,input().split())
A = list(map(int,input().split()))
pq = []
ans = 0

for a in A:
    heappush(pq, [-a, 1])
    
for _ in range(m):
    b,c = map(int,input().split())
    heappush(pq, [-c, b])

for i in range(n):
    c,b = heappop(pq)
    c = -c
    ans += c
    if b > 1:
        b -= 1
        heappush(pq, [-c, b])
        
print(ans)