Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from heapq import heapify,heapreplace
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    heapify(A)

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    for b,c in BC:
        if c<A[0]:
            break
        for i in range(b):
            if A[0]>c:
                break
            heapreplace(A,c)
        
    #print(A)
    print(sum(A))
if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
from heapq import heapify,heapreplace
def solve(stdin):
    n,m = stdin[:2]
    A = stdin[2:2+n].tolist()
    BC = stdin[2+n:].reshape(-1,2)

    heapify(A)

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    for b,c in BC:
        if c<A[0]:
            break
        for i in range(b):
            if A[0]>c:
                break
            heapreplace(A,c)
        
    #print(A)
    return sum(A)
 
def main():   
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    print(solve(stdin))
 
def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
 
if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
def solve(stdin):
    from heapq import heapify,heapreplace

    n,m = stdin[:2]
    A = stdin[2:2+n].tolist()
    BC = stdin[2+n:].reshape(-1,2)

    heapify(A)

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    for b,c in BC:
        if c<A[0]:
            break
        for i in range(b):
            if A[0]>c:
                break
            heapreplace(A,c)
        
    #print(A)
    return sum(A)
 
def main():
    
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    print(solve(stdin))
 
def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
 
if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from heapq import heapify,heapreplace

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

    heapify(A)

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    for b,c in BC:
        if c<A[0]:
            break
        for i in range(b):
            if A[0]>c:
                break
            heapreplace(A,c)
        
    #print(A)
    print(sum(A))
if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify,heapreplace
n,m = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(m)]

heapify(A)

BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
for b,c in BC:
    if c<A[0]:
        break
    for i in range(b):
        if A[0]>c:
            break
        heapreplace(A,c)
    
#print(A)
print(sum(A))


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify,heapreplace
n,m = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(m)]

A.sort()
heapify(A)

BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
for b,c in BC:
    if c<A[0]:
        break
    for i in range(b):
        if A[0]>c:
            break
        heapreplace(A,c)
    
#print(A)
print(sum(A))


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify,heapreplace
n,m = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(m)]

A.sort()
heapify(A)

BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
for b,c in BC:
    if c<A[0]:
        break
    for i in range(b):
        if A[0]>c:
            break
        heapreplace(A,c)
    
#print(A)
print(sum(A))


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
from heapq import heapify
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())

heapq.heapify(A)
for i in range(m):
    b,c = map(int,input().split())
    for i in range(b):
        if A[0]<c:
            heapq.heapreplace(A,c)
        else:
            break
print(sum(A))


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
from heapq import heapify
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())

heapq.heapify(A)
for i in range(m):
    b,c = B[i],C[i]
    for i in range(b):
        if A[0]<c:
            heapq.heapreplace(A,c)
        else:
            break
print(sum(A))


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))
if __name__=='__main__':
    main()