Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
b, c = [], []
heapq.heapify(a)

for i in range(m):
    v1, v2 = map(int, input().split())
    b.append(v1)
    c.append(v2)

for i in range(m):
    cnt = 0
    while True:
        if cnt == b[i]:
            break
        minV = heapq.heappop(a)
        #print('# minV: ' + str(minV))
        if minV >= c[i]:
            heapq.heappush(a, minV)
            break
        else:
            heapq.heappush(a, c[i])
        cnt += 1

#print(a)
print(sum(a))




Fixed submission:
import bisect
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
#b, c = [], []
bc = []
heapq.heapify(a)

for i in range(m):
    bc.append(list(map(int, input().split())))
    # v1, v2 = map(int, input().split())
    # b.append(v1)
    # c.append(v2)
bc.sort(key = lambda x: x[1], reverse=True)

for i in range(m):
    cnt = 0
    while True:
        if cnt == bc[i][0]:
            break
        minV = heapq.heappop(a)
        #print('# minV: ' + str(minV))
        if minV >= bc[i][1]:
            heapq.heappush(a, minV)
            break
        else:
            heapq.heappush(a, bc[i][1])
        cnt += 1

#print(a)
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import heapq
n, m = map(int, input().split())
#a = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
#a = list(map(lambda x: x * -1, a))
b, c = [], []

for i in range(m):
    v1, v2 = map(int, input().split())
    b.append(v1)
    c.append(v2)

#print(a)

for i in range(m):
    idx = bisect.bisect_left(a, c[i])
    #print('idx: ' + str(idx))
    cnt = min(idx, b[i])
    a = [c[i]] * cnt + a[cnt:]
    a.sort()

#print(a)
print(sum(a))




Fixed submission:
import bisect
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
#b, c = [], []
bc = []
heapq.heapify(a)

for i in range(m):
    bc.append(list(map(int, input().split())))
    # v1, v2 = map(int, input().split())
    # b.append(v1)
    # c.append(v2)
bc.sort(key = lambda x: x[1], reverse=True)

for i in range(m):
    cnt = 0
    while True:
        if cnt == bc[i][0]:
            break
        minV = heapq.heappop(a)
        #print('# minV: ' + str(minV))
        if minV >= bc[i][1]:
            heapq.heappush(a, minV)
            break
        else:
            heapq.heappush(a, bc[i][1])
        cnt += 1

#print(a)
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import heapq
n, m = map(int, input().split())
#a = sorted(list(map(int, input().split())))
a = list(map(int, input().split()))
#a = list(map(lambda x: x * -1, a))
b, c = [], []
heapq.heapify(a)

for i in range(m):
    v1, v2 = map(int, input().split())
    b.append(v1)
    c.append(v2)

for i in range(m):
    cnt = 0
    while True:
        if cnt == b[i]:
            break
        #minV = -heapq.heappop(a)
        minV = heapq.heappop(a)
        #print('# minV: ' + str(minV))
        if minV >= c[i]:
            heapq.heappush(a, minV)
            break
        else:
            heapq.heappush(a, c[i])
        cnt += 1

#print(a)
print(sum(a))




Fixed submission:
import bisect
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
#b, c = [], []
bc = []
heapq.heapify(a)

for i in range(m):
    bc.append(list(map(int, input().split())))
    # v1, v2 = map(int, input().split())
    # b.append(v1)
    # c.append(v2)
bc.sort(key = lambda x: x[1], reverse=True)

for i in range(m):
    cnt = 0
    while True:
        if cnt == bc[i][0]:
            break
        minV = heapq.heappop(a)
        #print('# minV: ' + str(minV))
        if minV >= bc[i][1]:
            heapq.heappush(a, minV)
            break
        else:
            heapq.heappush(a, bc[i][1])
        cnt += 1

#print(a)
print(sum(a))