n, m = list(map(int, input().split()))

cards = sorted(list(map(int, input().split())))

ope = [list(map(int, input().split())) for i in range(m)]

ope.sort(key=lambda x: x[1], reverse=True)

i, j, k = 0, 0, 0

while i < n and j < m and cards[i] < ope[j][1]:

    cards[i] = ope[j][1]

    i += 1

    k += 1

    if k >= ope[j][0]:

        j += 1

        k = 0

print((sum(cards)))
n, m = list(map(int, input().split()))

a = sorted([int(i) for i in input().split()])

bc = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x: x[1], reverse=True)

i = 0

for b, c in bc:

    while b:

        if i < n and a[i] < c:

            a[i] = c

            b -= 1

        else:

            break

        i += 1

print((sum(a)))
n, m = list(map(int, input().split()))
cards = sorted(list(map(int, input().split())))
ope = [list(map(int, input().split())) for i in range(m)]
ope.sort(key=lambda x: x[1], reverse=True)
i, j, k = 0, 0, 0
while i < n and j < m and cards[i] < ope[j][1]:
    cards[i] = ope[j][1]
    i += 1
    k += 1
    if k >= ope[j][0]:
        j += 1
        k = 0
print((sum(cards)))

n, m = list(map(int, input().split()))
a = sorted([int(i) for i in input().split()])
bc = sorted(
    [tuple(map(int, input().split())) for i in range(m)],
    key=lambda x: x[1],
    reverse=True,
)
i = 0
for b, c in bc:
    while b:
        if i < n and a[i] < c:
            a[i] = c
            b -= 1
        else:
            break
        i += 1
print((sum(a)))

-cards = sorted(list(map(int, input().split()))) -ope = [list(map(int, input().split())) for i in range(m)] -ope.sort(key=lambda x: x[1], reverse=True) -i, j, k = 0, 0, 0 -while i < n and j < m and cards[i] < ope[j][1]: -    cards[i] = ope[j][1] -    i += 1 -    k += 1 -    if k >= ope[j][0]: -        j += 1 -        k = 0 -print((sum(cards))) +a = sorted([int(i) for i in input().split()]) +bc = sorted( +    [tuple(map(int, input().split())) for i in range(m)], +    key=lambda x: x[1], +    reverse=True, +) +i = 0 +for b, c in bc: +    while b: +        if i < n and a[i] < c: +            a[i] = c +            b -= 1 +        else: +            break +        i += 1 +print((sum(a)))