Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

for _ in range(M):
    B, C = map(int, input().split())
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
print(sum(heap))

Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_A = list(map(int, input().split()))
for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        min_A = min(li_A)
        if min_A <C:
            li_A[li_A.index(min_A)] = C
        else:
            break
print(sum(li_A))

Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_A = list(map(int, input().split()))
for i in range(M):
    li_A.sort()
    B, C = map(int, input().split())
    for j in range(B):
        if li_A[j] < C:
            li_A[j] = C
        else:
            break
print(sum(li_A))

Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_A = list(map(int, input().split()))
for i in range(M):
    li_A.sort()
    B, C = map(int, input().split())
    for j in range(B):
        if li_A[j] < C:
            li_A[j] = C
print(sum(li_A))

Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
li = sorted(list(map(int, input().split())))

for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        if li[0] >= C:
            break
        li[0] = C
        li.sort()
print(sum(li))


Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
li = sorted(list(map(int, input().split())))

for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        if li[0] > C:
            break
        li[0] = C
        li.sort()
print(sum(li))


Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
li = list(map(int, input().split()))

for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        min_list = min(li)
        if min_list > C:
            break
        li[li.index(min_list)] = C
print(sum(li))


Fixed submission:
from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
heap = list(map(int, input().split()))
heapify(heap)

BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append([B, C])
BC.sort(key=lambda x: -x[1])

for B, C in BC:
    for _ in range(B):
        tmp = heappop(heap)
        if tmp < C:
            heappush(heap, C)
        else:
            heappush(heap, tmp)
            break
print(sum(heap))