Buggy python submission (verdict: Runtime Error):
import numpy as np
def main():
    N,M = map(int,input().split())
    A = [int(x) for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        for i in range(b):
            A.append(c)
    np.array(A).sort()
    print(sum(A[-N:]))
main()

Fixed submission:
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,M = map(int,input().split())
    A = [int(x) for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        for i in range(b):
            A.append(c)
    A.sort()
    print(sum(A[-N:]))
main()

Fixed submission:
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,M = map(int,input().split())
    A = [int(x) for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        for i in range(b):
            A.append(c)
    A.sort()
    print(sum(A[-N:]))
main()

Fixed submission:
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def main():
    N,M = map(int,input().split())
    A =[int(x) for x in input().split()]
    A.sort()
    for _ in range(M):
        b,c = map(int,input().split())
        k=0
        for i in range(b):
            if A[i]<c:
                A[i]=c
                k+=1
        a = bisect.bisect(A[k:],c)
        d,e = A[:a+k],A[a+k:]
        d.sort()
        A = d+e
    print(sum(A))
main()   

Fixed submission:
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,M = map(int,input().split())
    A =[int(x) for x in input().split()]
    A.sort()
    for _ in range(M):
        b,c = map(int,input().split())
        for i in range(b):
            if A[i]<c:
                A[i]=c
        A.sort()
    print(sum(A))
main()    

Fixed submission:
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()