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

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapify(A)

    for _ in range(M):
        b, c = map(int, input().split())
        for _ in range(b):
            m = heappop(A)
            if m >= c:
                heappush(A, m)
                break
            heappush(A, c)
    
    print(sum(A))


if __name__ == "__main__":
    main()

Fixed submission:
from heapq import heapify, heappush, heappop
from operator import itemgetter

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapify(A)

    query = [list(map(int, input().split())) for _ in range(M)]
    query.sort(key=itemgetter(1), reverse=True)

    for b, c in query:
        for _ in range(b):
            m = heappop(A)
            if m >= c:
                heappush(A, m)
                break
            heappush(A, c)
        else:
            continue
        break
    
    print(sum(A))


if __name__ == "__main__":
    main()

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

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapify(A)

    for _ in range(M):
        b, c = map(int, input().split())
        for _ in range(b):
            m = heappop(A)
            if m >= c:
                heappush(A, m)
                break
            heappush(A, c)
    
    print(sum(A))


if __name__ == "__main__":
    main()

Fixed submission:
from heapq import heapify, heappush, heappop
from operator import itemgetter

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapify(A)

    query = [list(map(int, input().split())) for _ in range(M)]
    query.sort(key=itemgetter(1), reverse=True)

    for b, c in query:
        for _ in range(b):
            m = heappop(A)
            if m >= c:
                heappush(A, m)
                break
            heappush(A, c)
        else:
            continue
        break
    
    print(sum(A))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from operator import itemgetter

N, M = map(int, input().split())
cards = sorted(list(map(int, input().split())))
candidates = [list(map(int, input().split())) for _ in range(M)]
candidates.sort(key=itemgetter(1), reverse=True)

for canditate in candidates:
    n_card = canditate[0]
    replace_value = canditate[1]
    if  replace_value  < cards[0]:
        break
    
    for i in range(n_card):
        if cards[i] < replace_value:
            cards[i] = replace_value
        else:
            break
    cards.sort()

print(sum(cards))

Fixed submission:
from heapq import heapify, heappush, heappop
from operator import itemgetter

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapify(A)

    query = [list(map(int, input().split())) for _ in range(M)]
    query.sort(key=itemgetter(1), reverse=True)

    for b, c in query:
        for _ in range(b):
            m = heappop(A)
            if m >= c:
                heappush(A, m)
                break
            heappush(A, c)
        else:
            continue
        break
    
    print(sum(A))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

N, M = map(int, input().split())
cards = sorted(list(map(int, input().split())))
candidates = [list(map(int, input().split())) for _ in range(M)]
candidates.sort(key=itemgetter(1), reverse=True)

for canditate in candidates:
    n_card = canditate[0]
    replace_value = canditate[1]
    if  replace_value  < cards[0]:
        break
        
    for i in range(n_card):
        if cards[i] < replace_value:
            cards[i] = replace_value
        else:
            break
    cards.sort()

print(sum(cards))

Fixed submission:
from heapq import heapify, heappush, heappop
from operator import itemgetter

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapify(A)

    query = [list(map(int, input().split())) for _ in range(M)]
    query.sort(key=itemgetter(1), reverse=True)

    for b, c in query:
        for _ in range(b):
            m = heappop(A)
            if m >= c:
                heappush(A, m)
                break
            heappush(A, c)
        else:
            continue
        break
    
    print(sum(A))


if __name__ == "__main__":
    main()