from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse = True)
ind = -1
now = -1
cnt = 0
for i in range(n):
    if cnt == 0:
        ind += 1
        if ind >= m: break
        cnt, now = bc[ind]
    if a[i] >= now:
        break
    a[i] = now
    cnt -= 1
print(sum(a)) from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys math itertools fractions pprint sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n,m = inpl() n inpl() inpl m a = inpl() a inpl() inpl a.sort() a.sort a sort inpl() for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) inpl() inpl bc = [inpl() for _ in range(m)] bc [inpl() for _ in range(m)] bc.sort(key=lambda x:x[1], reverse = True) bc.sort bc sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse = True reverse True ind = -1 ind -1 now = -1 now -1 cnt = 0 cnt 0 for i in range(n):
    if cnt == 0:
        ind += 1
        if ind >= m: break
        cnt, now = bc[ind]
    if a[i] >= now:
        break
    a[i] = now
    cnt -= 1 i range(n) range n if cnt == 0:
        ind += 1
        if ind >= m: break
        cnt, now = bc[ind]
     cnt == 0 cnt 0 ind += 1 ind 1 if ind >= m: break
         ind >= m ind m cnt, now = bc[ind] cnt bc[ind] bc ind now if a[i] >= now:
        break
     a[i] >= now a[i] a i now break a[i] = now a[i] a i now cnt -= 1 cnt 1 print(sum(a)) print sum(a) sum a mod = 10**9+7 10**9+7 mod ind += 1 1 ind ind = -1 -1 ind m = inpl() inpl() m def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl cnt, now = bc[ind] bc[ind] cnt cnt = 0 0 cnt INF = float('inf') float('inf') INF cnt -= 1 1 cnt bc = [inpl() for _ in range(m)] [inpl() for _ in range(m)] bc def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp a = inpl() inpl() a now = -1 -1 now now = bc[ind] bc[ind] now n,m = inpl() inpl() n
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse = True)
ind = -1
now = -1
cnt = 0
for i in range(n):
    if cnt == 0:
        ind += 1
        if ind >= m: break
        cnt, now = bc[ind]
    if a[i] >= now:
        break
    a[i] = now
    cnt -= 1
print(sum(a))