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 g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))

Fixed submission:
import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)

heapq.heapify(a)

for i in range(m):
    b,c=bc[i]
    for g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

for i in range(M):
	B,C = [int(i) for i in input().split()]
	for g in range(B):
		A.append(C)
A.sort(reverse=True)
print(sum(A[:N]))

Fixed submission:
import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)

heapq.heapify(a)

for i in range(m):
    b,c=bc[i]
    for g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

BClist = []
for i in range(M):
	B,C = [int(i) for i in input().split()]
	for g in range(B):
		BClist.append(C)
A.sort()
BClist.sort()

for i in range(len(BClist)):
	if A[i]<BClist[-1]:
		A[i]=BClist[-1]
		BClist.pop(-1)
	else:
		break
print(sum(A))

Fixed submission:
import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)

heapq.heapify(a)

for i in range(m):
    b,c=bc[i]
    for g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())  
A = [int(i) for i in input().split()]
BC = [[int(i) for i in input().split()] for i in range(M)] 	
BClist = []
for i in range(M):
	for g in range(BC[i][0]):
		BClist.append(BC[i][1])
A.sort()
BClist.sort()

for i in range(len(BClist)):
	if A[i]<BClist[-1]:
		A[i]=BClist[-1]
		BClist.pop(-1)
	else:
		break
print(sum(A))

Fixed submission:
import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)

heapq.heapify(a)

for i in range(m):
    b,c=bc[i]
    for g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))