Buggy python submission (verdict: Time Limit Exceeded):
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if min(A) < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
  
print(check())

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

Buggy python submission (verdict: Time Limit Exceeded):
def check():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    for cnt, value in sousa:
        for i in range(cnt):
            if min(A) < value:
                A[A.index(min(A))] = value
            else:
                return(sum(A))
    return(sum(A))
  
print(check())

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
sousa = sorted([[int(i) for i in input().split()] for i in range(M)], reverse=True, key=lambda x:x[1])
for cnt, value in sousa:
    for i in range(cnt):
        if min(A) < value:
            A[A.index(min(A))] = value
        else:
            return(sum(A))
return(sum(A))

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
               reverse=True, key=lambda x:x[1])
print(sousa)
for cnt, v in sousa:
    for i in range(cnt):
        if min(A) < v:
            A[A.index(min(A))] = v
        else:
            return(sum(A))
return(sum(A))

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
               reverse=True, key=lambda x:x[1])
print(sousa)
for cnt, value in sousa:
    for i in range(cnt):
        if min(A) < value:
            A[A.index(min(A))] = value
        else:
            return(sum(A))
return(sum(A))

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

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

for cnt, value in C:
    for _ in range(cnt):
        if A[index] >= value:
            flag = True
            break
        A[index] = value
        index += 1
    if flag: break
print(sum(A))

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

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

for cnt, value in C:
    for _ in range(cnt):
        if A[index] >= value:
            break
        A[index] = value
        index += 1
print(sum(A))

Fixed submission:
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())