Buggy python submission (verdict: Runtime Error):
#include<vector>
#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<long long int> A(N);
    for(int i = 0; i<N; i++) {
        cin >> A.at(i);
    }
    for(int j = 0; j<M; j++) {
        long long int b, c;
        cin >> b >> c;
        vector<long long int> x(b,c);
        A.insert(A.end(), x.begin(), x.end());
    }
    sort(A.begin(), A.end(), std::greater<long long int>());
    cout << accumulate(A.begin(), A.begin()+N, 0LL) << endl;
    return 0;
}

Fixed submission:
from collections import defaultdict
inf = input().split()
N = int(inf[0])
W = int(inf[1])
dic = defaultdict(int)

line = input().split()

for a in line:
    dic[int(a)] += 1

for w in range(W):
    inf = input().split()
    b = int(inf[0])
    c = int(inf[1])
    dic[c] += b
    
keys = list(dic.keys())

keys.sort(reverse=True)

count = 0
ans = 0
for k in keys:
    while dic[k]>0:
        if count == N:
            break
        ans += k
        dic[k] -= 1
        count += 1
    if count == N:
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = input().split()
N = int(inf[0])
M = int(inf[1])
cards = [int(a) for a in input().split()]
for i in range(M):
  inf = input().split()
  C = int(inf[0])
  B = int(inf[1])
  cards += [B]*C

cards.sort(reverse=True)

print(sum(cards[:N]))


Fixed submission:
from collections import defaultdict
inf = input().split()
N = int(inf[0])
W = int(inf[1])
dic = defaultdict(int)

line = input().split()

for a in line:
    dic[int(a)] += 1

for w in range(W):
    inf = input().split()
    b = int(inf[0])
    c = int(inf[1])
    dic[c] += b
    
keys = list(dic.keys())

keys.sort(reverse=True)

count = 0
ans = 0
for k in keys:
    while dic[k]>0:
        if count == N:
            break
        ans += k
        dic[k] -= 1
        count += 1
    if count == N:
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = input().split()
N = int(inf[0])
M = int(inf[1])
cards = [int(a) for a in input().split()]
for i in range(M):
  inf = input().split()
  C = int(inf[0])
  B = int(inf[1])
  cards += [B]*C

cards.sort(reverse=True)

print(sum(cards[:N]))

Fixed submission:
from collections import defaultdict
inf = input().split()
N = int(inf[0])
W = int(inf[1])
dic = defaultdict(int)

line = input().split()

for a in line:
    dic[int(a)] += 1

for w in range(W):
    inf = input().split()
    b = int(inf[0])
    c = int(inf[1])
    dic[c] += b
    
keys = list(dic.keys())

keys.sort(reverse=True)

count = 0
ans = 0
for k in keys:
    while dic[k]>0:
        if count == N:
            break
        ans += k
        dic[k] -= 1
        count += 1
    if count == N:
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = input().split()
N = int(inf[0])
M = int(inf[1])
cards = [int(a) for a in input().split()]
cards.sort()
for i in range(M):
  inf = input().split()
  C = int(inf[0])
  B = int(inf[1])
  i = 0
  while cards[i] < B:
    cards[i] = B
    i+=1
    C -= 1
    if C==0:
      break
  cards.sort()

print(sum(cards))

Fixed submission:
from collections import defaultdict
inf = input().split()
N = int(inf[0])
W = int(inf[1])
dic = defaultdict(int)

line = input().split()

for a in line:
    dic[int(a)] += 1

for w in range(W):
    inf = input().split()
    b = int(inf[0])
    c = int(inf[1])
    dic[c] += b
    
keys = list(dic.keys())

keys.sort(reverse=True)

count = 0
ans = 0
for k in keys:
    while dic[k]>0:
        if count == N:
            break
        ans += k
        dic[k] -= 1
        count += 1
    if count == N:
        break

print(ans)