Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
list_num = list(map(int, input().split()))
# list_num_ar = np.array(list_num)
# print(list_num)
for i in range(M):
	a, b = map(int, input().split())
	res = [b]*a
	# print(res)
	list_num = list_num + res

list_num_ar = sorted(list_num, reverse=True) 
# print(list_num_ar[0:N])
print(sum(list_num_ar[0:N]))

Fixed submission:
from sys import stdin
 
def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()
 
    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)
 
    ans = 0
    minIndex = 0
    isFinished = False
 
    for b,c in bcs:
 
        for _ in range(b):
            if minIndex < n and cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break
 
    if minIndex < n:
        ans += sum(cards[minIndex:])
 
    print(ans)
    
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M = map(int, input().split())
list_num = list(map(int, input().split()))
list_num_ar = np.array(list_num)
result = []

for i in range(M):
	a, b = map(int, input().split())
	res_a = list_num_ar[list_num_ar >= b]
	# print(res_a)
	res_b = list_num_ar[list_num_ar < b]
	# print(res_b)

	if a >= res_b.size:
		res_b = np.full(res_b.size, b)
	else:
		res_b = np.sort(res_b)
		res_b[0:a] = b
	# print(res_b)
	tmp = sum(res_b) + sum(res_a)
	result.append(tmp)

	list_num_ar = np.r_[res_a, res_b]
	# print(list_num_ar)

print(int(max(result)))

Fixed submission:
from sys import stdin
 
def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()
 
    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)
 
    ans = 0
    minIndex = 0
    isFinished = False
 
    for b,c in bcs:
 
        for _ in range(b):
            if minIndex < n and cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break
 
    if minIndex < n:
        ans += sum(cards[minIndex:])
 
    print(ans)
    
if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, M = map(int, input().split())
list_num = list(map(int, input().split()))
list_num_ar = np.array(list_num)
result = []

for i in range(M):
	a, b = map(int, input().split())
	res_a = list_num_ar[list_num_ar >= b]
	res_b = list_num_ar[list_num_ar < b]

	if a >= res_b.size:
		res_b = np.full(b, res_b.size)
	else:
		res_b = np.sort(res_b)
		res_b[0:a] = b

	tmp = sum(res_b) + sum(res_a)
	list_num_ar = np.r_[res_a, res_b]


	result.append(tmp)

print(max(result))

Fixed submission:
from sys import stdin
 
def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()
 
    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)
 
    ans = 0
    minIndex = 0
    isFinished = False
 
    for b,c in bcs:
 
        for _ in range(b):
            if minIndex < n and cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break
 
    if minIndex < n:
        ans += sum(cards[minIndex:])
 
    print(ans)
    
if __name__=='__main__':
    main()

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

result = []
for i in range(M):
	a, b = map(int, input().split())
	res_a = [k for k in list_num if k >= b]
	# print(res_a)

	res_b = [k for k in list_num if k < b]
	res_b = sorted(res_b)

	for j in range(min([a, len(res_b)])):
		res_b[j] = b

	# print(res_b)

	tmp = sum(res_b) + sum(res_a)
	# print(tmp)

	list_num = copy.copy(res_a)
	list_num.extend(res_b)
	# print(list_num)

	result.append(tmp)

print(max(result))

Fixed submission:
from sys import stdin
 
def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()
 
    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)
 
    ans = 0
    minIndex = 0
    isFinished = False
 
    for b,c in bcs:
 
        for _ in range(b):
            if minIndex < n and cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break
 
    if minIndex < n:
        ans += sum(cards[minIndex:])
 
    print(ans)
    
if __name__=='__main__':
    main()