Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = lambda x:x[1],reverse=True)

def exchange_cards(cards,exchange):
  cards.sort()
  count = 0
  for i in range(len(cards)):
    if (exchange[1] > cards[i])and(exchange[0] > count):
      cards[i] = exchange[1]
      count += 1
    else:
      break
  return cards
      
for i in range(M):
  cards = exchange_cards(cards,exchange_lists[i])
print(np.sum(cards))

Fixed submission:
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = lambda x:x[1],reverse=True)
cards.sort()
count = 0
for i in range(M):
  exchange=exchange_lists[i]
  num = 0
  for j in range(count,N):
    if (exchange[1] > cards[j])and(exchange[0] > num):
      cards[j] = exchange[1]
      count += 1
      num+=1
    else:
      break
  
print(np.sum(cards))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = itemgetter(1))
def exchange_cards(cards,exchange):
  cards.sort()
  count = 0
  for i in range(len(cards)):
    if (exchange[1] > cards[i])and(exchange[0] > count):
      cards[i] = exchange[1]
      count += 1
    else:
      break
  return cards
      
for i in range(M):
  cards = exchange_cards(cards,exchange_lists[i])
print(np.sum(cards))

Fixed submission:
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = lambda x:x[1],reverse=True)
cards.sort()
count = 0
for i in range(M):
  exchange=exchange_lists[i]
  num = 0
  for j in range(count,N):
    if (exchange[1] > cards[j])and(exchange[0] > num):
      cards[j] = exchange[1]
      count += 1
      num+=1
    else:
      break
  
print(np.sum(cards))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))

def exchange_cards(cards,exchange):
  cards.sort()
  for i in range(len(cards)):
    if (exchange[1] > cards[i])and(exchange[0] > i):
      cards[i] = exchange[1]
    else:
      break
  return cards
      
for i in range(M):
  cards = exchange_cards(cards,exchange_lists[i])
print(np.sum(cards))

Fixed submission:
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = lambda x:x[1],reverse=True)
cards.sort()
count = 0
for i in range(M):
  exchange=exchange_lists[i]
  num = 0
  for j in range(count,N):
    if (exchange[1] > cards[j])and(exchange[0] > num):
      cards[j] = exchange[1]
      count += 1
      num+=1
    else:
      break
  
print(np.sum(cards))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))

def exchange_cards(cards,exchange):
  cards.sort()
  count = 0
  for i in range(len(cards)):
    if (exchange[1] > cards[i])and(exchange[0] > count):
      cards[i] = exchange[1]
      count += 1
    else:
      break
  return cards
      
for i in range(M):
  cards = exchange_cards(cards,exchange_lists[i])
print(np.sum(cards))

Fixed submission:
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = lambda x:x[1],reverse=True)
cards.sort()
count = 0
for i in range(M):
  exchange=exchange_lists[i]
  num = 0
  for j in range(count,N):
    if (exchange[1] > cards[j])and(exchange[0] > num):
      cards[j] = exchange[1]
      count += 1
      num+=1
    else:
      break
  
print(np.sum(cards))