Buggy python submission (verdict: Time Limit Exceeded):
import collections
n, m = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
total_counter = collections.Counter([])

for i in range(m):
    b, c =  [ int(v) for v in input().split() ]
    total_counter[c] += b
for i in num_list:
    total_counter[i] += 1


total_counter_2 = list(zip(total_counter.keys(), total_counter.values()))

ans_list = []
c = 0
for i in sorted(total_counter_2,reverse = True):
    p, q = i
    for j in range(q):
        ans_list.append(p)
    c += q
    if c >= n:
        break
print(sum(ans_list[:n]))


Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

import collections
n, m = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
total_counter = collections.Counter(num_list)
for i in range(m):
    b, c =  [ int(v) for v in input().split() ]
    total_counter[c] += b


total_counter_2 = list(zip(total_counter.keys(), total_counter.values()))

ans_list = []
c = 0
for i in sorted(total_counter_2,reverse = True):
    p, q = i
    for j in range(q):
        ans_list.append(p)
    c += q
    if c >= n:
        break
print(sum(ans_list[:n]))

Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = [ int(v) for v in input().split() ]
num_list = sorted([ -int(v) for v in input().split() ])

for i in range(m):
	a, b = [ int(v) for v in input().split() ]
	for j in range(a):
		heapq.heappush(num_list,-b)

ans = 0
for i in range(n):
	ans += heapq.heappop(num_list)

print(-ans)

Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = [ int(v) for v in input().split() ]
num_list = sorted([ -int(v) for v in input().split() ])

for i in range(m):
	a, b = [ int(v) for v in input().split() ]
	for j in range(a):
		heapq.heappush(num_list,-b)

ans = 0
for i in range(n):
	ans += heapq.heappop(num_list)

print(-ans)

Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Runtime Error):

n, m = [ int(v) for v in input().split() ]
num_list = sorted([ -int(v) for v in input().split() ])

for i in range(m):
	a, b = [ int(v) for v in input().split() ]
	for j in range(a):
		heapq.heappush(num_list,-b)

ans = 0
for i in range(n):
	ans += heapq.heappop(num_list)

print(-ans)

Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, m = [ int(v) for v in input().split() ]
num_list = sorted([ int(v) for v in input().split() ])
change_list = []
for i in range(m):
	a,b = [ int(v) for v in input().split() ]
	change_list += [b]*a
change_list = sorted(change_list,reverse = True)

x = len(change_list)
if n >= x:
	change_list += ([0]*(n-x))
else:
	change_list = change_list[:n]


anslist = [ max(num_list[i], change_list[i])for i in range(n)]
print(sum(anslist))


Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

n, m = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
change_list = []
for i in range(m):
	a,b = [ int(v) for v in input().split() ]
	change_list += [b]*a


anslist = sorted(num_list+change_list, reverse = True)
print(sum(anslist[:n]))

Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, m = [ int(v) for v in input().split() ]
num_list = sorted([ int(v) for v in input().split() ])
change_list = []
for i in range(m):
	a,b = [ int(v) for v in input().split() ]
	change_list += [b]*a
change_list = sorted(change_list,reverse = True)

x = len(change_list)
if n >= x:
	change_list += ([0]*(n-x))
else:
	change_list = change_list[:n]


anslist = [ max(num_list[i], change_list[i])for i in range(n)]
print(sum(anslist))


Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):


n, m = [ int(v) for v in input().split() ]
num_list = sorted([ int(v) for v in input().split() ])
change_list = []
for i in range(m):
	a,b = [ int(v) for v in input().split() ]
	change_list += [b]*a
change_list = sorted(change_list,reverse = True)

x = len(change_list)
if n >= x:
	change_list += ([0]*(n-x))
else:
	change_list = change_list[:n]


anslist = [ max(num_list[i], change_list[i])for i in range(n)]
print(sum(anslist))


Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)