Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]

for b, c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
print(sum(heap))

Fixed submission:
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])#cが大きいものから順に操作を加える

for b,c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
      break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
num = list(map(int, input().split()))
for i in range(m):
  num.sort()
  cnt, changeNum = map(int, input().split())
  for j in range(cnt):
    if num[j] >= changeNum:
      break
    else:
      num[j] = changeNum
print(sum(num))

Fixed submission:
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])#cが大きいものから順に操作を加える

for b,c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
      break
print(sum(heap))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())
num = list(map(int, input().split()))
for i in range(m):
  num.sort()
  cnt, changeNum = map(int, input().split())
  for j in range(cnt):
    if num[j] >= changeNum:
      break
    else:
      num[j] = changeNum
print(sum(num))

Fixed submission:
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])#cが大きいものから順に操作を加える

for b,c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
      break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, m = map(int, input().split())
num = list(map(int, input().split()))
for i in range(m):
  num.sort()
  cnt, changeNum = map(int, input().split())
  for j in range(cnt):
    if num[j] >= changeNum:
      break
    else:
      num[j] = changeNum
print(sum(num))

Fixed submission:
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])#cが大きいものから順に操作を加える

for b,c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
      break
print(sum(heap))