Buggy python submission (verdict: Time Limit Exceeded):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from heapq import heapify, heappush, heappop

def main():
    n, m = MII()
    a_lst = MII()
    heapify(a_lst)
    for i in range(m):
        b, c = MII()
        for i in range(b):
            minv = a_lst[0]
            if minv < c: heappop(a_lst); heappush(a_lst, c)
            else: break
    print(sum(a_lst))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from heapq import heapify, heappush, heappop

def main():
    n, m = MII()
    a_lst = MII()
    a_lst.sort()
    bc = []
    for i in range(m):
        b, c= MII()
        bc.append((b,c))
    bc.sort(key=lambda x: x[1], reverse=True)
    index = 0
    cnt = 0
    for i in range(n):
        if a_lst[i] > bc[index][1]: break
        a_lst[i] = bc[index][1]
        cnt += 1
        if cnt == bc[index][0]:
            cnt = 0
            index += 1
            if index == m:
                break
    print(sum(a_lst))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from heapq import heapify, heappush, heappop

def main():
    n, m = MII()
    a_lst = MII()
    heapify(a_lst)
    for i in range(m):
        b, c = MII()
        for i in range(b):
            minv = a_lst[0]
            if minv < c: heappop(a_lst); heappush(a_lst, c)
            else: break
    print(sum(a_lst))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from heapq import heapify, heappush, heappop

def main():
    n, m = MII()
    a_lst = MII()
    a_lst.sort()
    bc = []
    for i in range(m):
        b, c= MII()
        bc.append((b,c))
    bc.sort(key=lambda x: x[1], reverse=True)
    index = 0
    cnt = 0
    for i in range(n):
        if a_lst[i] > bc[index][1]: break
        a_lst[i] = bc[index][1]
        cnt += 1
        if cnt == bc[index][0]:
            cnt = 0
            index += 1
            if index == m:
                break
    print(sum(a_lst))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
import numpy as np

def main():
    n, m = MII()
    a_lst = np.array(sorted(MII()))
    for i in range(m):
        b, c = MII()
        idx = np.searchsorted(a_lst, c, side='left')
        if idx <= b:
            a_lst[:idx] = c
        else:
            a_lst[:b] = c
        a_lst.sort()
    print(np.sum(a_lst))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from heapq import heapify, heappush, heappop

def main():
    n, m = MII()
    a_lst = MII()
    a_lst.sort()
    bc = []
    for i in range(m):
        b, c= MII()
        bc.append((b,c))
    bc.sort(key=lambda x: x[1], reverse=True)
    index = 0
    cnt = 0
    for i in range(n):
        if a_lst[i] > bc[index][1]: break
        a_lst[i] = bc[index][1]
        cnt += 1
        if cnt == bc[index][0]:
            cnt = 0
            index += 1
            if index == m:
                break
    print(sum(a_lst))

if __name__ == '__main__':
    main()