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

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            D.append(C)

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            if len(D) != N:
                D.append(C)
            else:
                break
        else:
            continue
        break

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,reverse=True,key=lambda x: x[1])
D = []

for B,C in BC:
    for b in range(B):
        D.append(C)

for i in range(len(D)):
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break

print(sum(A))

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            if len(D) != N:
                D.append(C)
            else:
                break
        else:
            continue
        break

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,reverse=True,key=lambda x: x[1])
D = []
i = 0

for B,C in BC:
    for b in range(B):
        D.append(C)

for a,d in zip(A,D):
    if a < d:
        A[i] = D[i]
    i += 1

print(sum(A))

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            if len(D) != N:
                D.append(C)
            else:
                break
        else:
            continue
        break

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,reverse=True,key=lambda x: x[1])
i = 0

for B,C in BC:
    if A[i] > C:
        break
    for a in A[i:]:
        if a < C and B != 0:
            A[i] = C
            B -= 1
            i += 1
        else:
            break
print(sum(A))

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            if len(D) != N:
                D.append(C)
            else:
                break
        else:
            continue
        break

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import heapq

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,reverse=True,key=lambda x: x[1])
i = 0

for B,C in BC:
    if A[i] >= C:
        break
    for a in A[i:]:
        if a < C and B != 0:
            A[i] = C
            B -= 1
            i += 1
        else:
            break
print(sum(A))

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            if len(D) != N:
                D.append(C)
            else:
                break
        else:
            continue
        break

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()

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

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,reverse=True,key=lambda x: x[1])
i = 0

for B,C in BC:
    for a in A[i:]:
        if a < C and B != 0:
            A[i] = C
            B -= 1
            i += 1
        else:
            break
print(sum(A))

Fixed submission:
import sys

def input():
    return sys.stdin.readline().strip()

def main():

    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = [list(map(int,input().split())) for _ in range(M)]
    BC = sorted(BC,reverse=True,key=lambda x: x[1])
    D = []

    for B,C in BC:
        for b in range(B):
            if len(D) != N:
                D.append(C)
            else:
                break
        else:
            continue
        break

    for i in range(len(D)):
        if A[i] < D[i]:
            A[i] = D[i]
        else:
            break

    print(sum(A))

if __name__ == "__main__":
    main()