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

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
reinfo = info[0:n]
#print(a)

heapq.heapify(a)
#print(a)

d = 0

for j in range(len(reinfo)):
    for k in range(reinfo[j][0]):
        if a[0] > reinfo[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,reinfo[j][1])
    if d == 1:
        break

print(sum(a))

Fixed submission:
import heapq

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
#print(a)

heapq.heapify(a)
#print(a)

d = 0
count = 0

for j in range(len(info)):
    for k in range(info[j][0]):
        if a[0] > info[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,info[j][1])
            count += 1
        if count >= n:
            d = 1
            break
    if d == 1:
        break

print(sum(a))

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

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
#print(a)

heapq.heapify(a)
#print(a)

d = 0

for j in range(m):
    for k in range(info[j][0]):
        if a[0] > info[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,info[j][1])
    if d == 1:
        break

print(sum(a))

Fixed submission:
import heapq

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
#print(a)

heapq.heapify(a)
#print(a)

d = 0
count = 0

for j in range(len(info)):
    for k in range(info[j][0]):
        if a[0] > info[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,info[j][1])
            count += 1
        if count >= n:
            d = 1
            break
    if d == 1:
        break

print(sum(a))

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

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

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

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

#print(a)

heapq.heapify(a)
#print(a)

for j in range(m):
    for k in range(b[j]):
        #if a[0] > c[j]:
        #    break
        #else:
        heapq.heappushpop(a,c[j])

print(sum(a))

Fixed submission:
import heapq

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
#print(a)

heapq.heapify(a)
#print(a)

d = 0
count = 0

for j in range(len(info)):
    for k in range(info[j][0]):
        if a[0] > info[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,info[j][1])
            count += 1
        if count >= n:
            d = 1
            break
    if d == 1:
        break

print(sum(a))

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

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

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

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

#print(a)

heapq.heapify(a)
#print(a)

for j in range(m):
    for k in range(b[j]):
        if a[0] > c[j]:
            break
        else:
            heapq.heappushpop(a,c[j])

print(sum(a))

Fixed submission:
import heapq

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
#print(a)

heapq.heapify(a)
#print(a)

d = 0
count = 0

for j in range(len(info)):
    for k in range(info[j][0]):
        if a[0] > info[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,info[j][1])
            count += 1
        if count >= n:
            d = 1
            break
    if d == 1:
        break

print(sum(a))