Buggy python submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A = deque(A)


BC = [list(map(int, input().split())) for i in range(M)]
BC.sort(key=lambda x: x[1])
D = deque([])
for i in range(M):
        D.extend([BC[i][1]] * BC[i][0])


sum = 0
for i in range(N):
        if A[-1] >= D[-1]:
                sum += A.pop()
        else:
                sum += D.pop()

print(sum)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

Buggy python submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A = deque(A)

print(A)

BC = [list(map(int, input().split())) for i in range(M)]
BC.sort(key=lambda x: x[1])
D = deque([])
for i in range(M):
        D.extend([BC[i][1]] * BC[i][0])

print(D)

sum = 0
for i in range(N):
        if A[-1] >= D[-1]:
                sum += A.pop()
        else:
                sum += D.pop()

print(sum)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
 
for i in range(M):
        B, C = map(int, input().split())
        for k in range(B):
                heapq.heappush(A, C)

sum = sum(heapq.nlargest(N, A))

print(sum)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
 
for i in range(M):
        B, C = map(int, input().split())
        if C <= A[0]:
                pass
        else:
                idx = 0
                for k in range(N):
                        if A[k] < C:
                                idx = k
                        else:
                                break
 
 
                if idx + 1 <= B:
                        A = [C for i in range(idx+1)] + A[idx + 1:]
                else:
                        A = A[B:idx+1] + [C for i in range(B)] + A[idx+1:]
 
        
 
print(sum(A))

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for i in range(M):
        B, C = map(int, input().split())
        if C <= A[0]:
                pass
        else:
                idx = 0
                for k in range(N):
                        if A[k] < C:
                                idx = k
                        else:
                                break


                if idx + 1 <= B:
                        for l in range(idx+1):
                                A[l] = C
                else:
                        A = A[B:idx+1] + [C for i in range(B)] + A[idx+1:]

        

print(sum(A))

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
print(A)

for i in range(M):
        B, C = map(int, input().split())
        if C <= A[0]:
                pass
        else:
                idx = 0
                for k in range(N):
                        if A[k] < C:
                                idx = k
                        else:
                                break
                print(idx)

                if idx + 1 <= B:
                        for l in range(idx+1):
                                A[l] = C
                else:
                        A = A[B:idx+1] + [C for i in range(B)] + A[idx+1:]

        print(A)

print(sum(A))

Fixed submission:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)