Buggy python submission (verdict: Time Limit Exceeded):
import sys,heapq
input = sys.stdin.readline
 
N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
rep = []
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [-c]*b
    rep += tmp
heapq.heapify(rep)
 
for i in range(N):
    A[i] = -1 * heapq.heappushpop(rep,-1*A[i])
print(sum(A))

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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t= t + [b]*a
        
        if len(t) >=N:
            break

    A = A+ t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])

    cnt = 0
    t = []
    for a,b in tmp:
        t=t+[b]*a
        cnt+= a
        if cnt >=N:
            break

    A = A + t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])

cnt = 0
t = []
for a,b in tmp:
    t=t+[b]*a
    cnt+= a
    if cnt >=N:
        break

A = A + t
A.sort(reverse = 1)
print(sum(A[:N]))



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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])

cnt = 0
t = []
for a,b in tmp:
    t=t+[b]*a
    cnt+= a
    if cnt >=N:
        break

A = A + t
A.sort(reverse = 1)
print(sum(A[:N]))



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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Amin = min(A)
tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])

cnt = 0
t = []
for a,b in tmp:
    t=t+[b]*a
    cnt+= a
    if cnt >=N:
        break
    if cnt<N and b <= A[cnt-1]:
        break
A = A + t
A.sort(reverse = 1)
print(sum(A[:N]))

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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Amin = min(A)
tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])

cnt = 0
t = []
for a,b in tmp:
    t=t+[b]*a
    cnt+= a
    if cnt >=N:
        break
    if cnt<N and b <= A[cnt-1]:
        break
for i in range(min(N,len(t))):
    if A[i] < t[i]:
        A[i] = t[i]
print(sum(A))



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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Amin = min(A)
tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])

cnt = 0
t = []
for i in range(M):
    t=t+[tmp[i][1]]*tmp[i][0]
    cnt+= tmp[i][0]
    if cnt >=N:
        break
    if cnt<N and tmp[i][1] <= A[cnt-1]:
        break
for i in range(min(N,len(t))):
    if A[i] < t[i]:
        A[i] = t[i]
print(sum(A))



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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
if tmp != []:
    for i in range(M):
        t=t+[tmp[i][1]]*tmp[i][0]
        cnt+= tmp[i][0]
        if cnt >=N:
            break
        if cnt<N and tmp[i][1] <= A[cnt-1]:
            break
for i in range(min(N,len(t))):
    if A[i] < t[i]:
        A[i] = t[i]
print(sum(A))



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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
if tmp != []:
    for i in range(M):
        t=t+[tmp[i][1]]*tmp[i][0]
        cnt+= tmp[i][0]
        if cnt >=N:
            break
        if cnt<N and tmp[i][1] <= A[cnt-1]:
            break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
if tmp != []:
    for i in range(M):
        t=t+[tmp[i][1]]*tmp[i][0]
        cnt+= tmp[i][0]
        if cnt >=N:
            break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

Buggy python submission (verdict: Runtime Error):
	import sys
input = sys.stdin.readline

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
if tmp != []:
    for i in range(M):
        t=t+[tmp[i][1]]*tmp[i][0]
        cnt+= tmp[i][0]
        if cnt >=N:
            break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
Amin = min(A)
tmp = []
for _ in range(M):
    a,b= list(map(int,input().split()))
    if b>=Amin:
        tmp.append([a,b])

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
for i in range(M):
    t=t+[tmp[i][1]]*tmp[i][0]
    cnt+= tmp[i][0]
    if cnt >=N:
        break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
tmp = []
for _ in range(M):
    tmp.append( list(map(int,input().split())))

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
for i in range(M):
    t=t+[tmp[i][1]]*tmp[i][0]
    cnt+= tmp[i][0]
    if cnt >=N:
        break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
tmp = []
for _ in range(M):
    tmp.append( list(map(int,input().split())))

tmp = sorted(tmp,key = lambda x:-x[1])
cnt = 0
t = []
for i in range(M):
    t=t+[tmp[i][1]]*tmp[i][0]
    cnt+= tmp[i][0]
    if cnt >=N:
        break
A = sorted(A+t,reverse = 1)

print(sum(A[:N]))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [c]*b
    A = sorted(A + tmp,reverse=1)[:N]
print(sum(A))

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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [c]*b
    A = sorted(A + tmp,reverse=1)[:N]
print(sum(A))

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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [c]*b
    A = A + tmp
A=sorted(A,reverse=1)[:N]
print(sum(A))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
rep = []
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [-c]*b
    rep = rep+tmp
rep=sorted(rep,reverse=1)[:N]
heapq.heapify(rep)

for i in range(N):
    if A[i] < -1 * rep[0]:
        heapq.heappush(rep,-1*A[i])
        A[i] = -1 * heapq.heappop(rep)
print(sum(A))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
rep = []
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [-c]*b
    rep = rep+tmp
heapq.heapify(rep)

for i in range(N):
    if A[i] < -1 * rep[0]:
        heapq.heappush(rep,-1*A[i])
        A[i] = -1 * heapq.heappop(rep)
print(sum(A))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
rep = []
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [-c]*b
    rep = rep+tmp
heapq.heapify(rep)

for i in range(N):
    A[i] = -1 * heapq.heappushpop(rep,-1*A[i])
print(sum(A))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()

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

N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
rep = []
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [-c]*b
    rep = rep+tmp
heapq.heapify(rep)

for i in range(N):
    A[i] = -1 * heapq.heappushpop(rep,-1*A[i])
print(sum(A))


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

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

if __name__ == '__main__':
    sol()