Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy as np

# TESTCASE #
test = ""
#test = \
"""
3 2
5 1 4
2 3
1 5
ans:
14
"""

"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
ans:
338
"""

"""
3 2
100 100 100
3 99
3 99
ans:
300
"""

"""
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
ans:
10000000001
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
### MAIN ###
        
n, m = map(int, input2().split())
a = np.array(list(map(int, input2().split())), dtype="int64")
bcs = [tuple(map(int, input2().split()))[::-1] for _ in range(m)]

a.sort()
bcs = sorted(bcs, reverse=True)

i = 0
for query in bcs:
    #print(query)
    if a[i] < query[0]:
        a[i:i+query[1]] = np.maximum(a[i:i+query[1]], query[0])
        i += query[1]
        #print(a)
    
print(np.sum(a))
    










Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np

# TESTCASE #
test = ""
#test = \
"""
3 2
5 1 4
2 3
1 5
ans:
14
"""

"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
ans:
338
"""

"""
3 2
100 100 100
3 99
3 99
ans:
300
"""

"""
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
ans:
10000000001
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
### MAIN ###
        
n, m = map(int, input2().split())
a = np.array(list(map(int, input2().split())), dtype="int64")
bcs = [tuple(map(int, input2().split()))[::-1] for _ in range(m)]

a.sort()
bcs = sorted(bcs, reverse=True)

i = 0
for query in bcs:
    #print(query)
    a[i:i+query[1]] = np.maximum(a[i:i+query[1]], query[0])
    i += query[1]
    #print(a)    
print(np.sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import numpy as np

# TESTCASE #
test = ""
#test = \
"""
3 2
5 1 4
2 3
1 5
ans:
14
"""

"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
ans:
338
"""

"""
3 2
100 100 100
3 99
3 99
ans:
300
"""

"""
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
ans:
10000000001
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
### MAIN ###
        
n, m = map(int, input2().split())
a = np.array(list(map(int, input2().split())))
bcs = [tuple(map(int, input2().split())) for _ in range(m)]
bcs.sort()

for query in bcs:
    
    a.sort()
    a[:query[0]] = np.maximum(a[:query[0]], query[1])
    
    
print(np.sum(a))
    










Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np

# TESTCASE #
test = ""
#test = \
"""
3 2
5 1 4
2 3
1 5
ans:
14
"""

"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
ans:
338
"""

"""
3 2
100 100 100
3 99
3 99
ans:
300
"""

"""
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
ans:
10000000001
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
### MAIN ###
        
n, m = map(int, input2().split())
a = np.array(list(map(int, input2().split())), dtype="int64")
bcs = [tuple(map(int, input2().split()))[::-1] for _ in range(m)]

a.sort()
bcs = sorted(bcs, reverse=True)

i = 0
for query in bcs:
    #print(query)
    a[i:i+query[1]] = np.maximum(a[i:i+query[1]], query[0])
    i += query[1]
    #print(a)    
print(np.sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

# TESTCASE #
test = ""
#test = \
"""
3 2
5 1 4
2 3
1 5
ans:
14
"""

"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
ans:
338
"""

"""
3 2
100 100 100
3 99
3 99
ans:
300
"""

"""
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
ans:
10000000001
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
### MAIN ###
        
n, m = map(int, input2().split())
a = list(map(int, input2().split()))
bcs = [tuple(map(int, input2().split())) for _ in range(m)]
bcs.sort()

for query in bcs:
    a.sort()
    for qi in range(query[0]):
        a[qi] = max(a[qi], query[1])
    
print(sum(a))
    

  


Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np

# TESTCASE #
test = ""
#test = \
"""
3 2
5 1 4
2 3
1 5
ans:
14
"""

"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
ans:
338
"""

"""
3 2
100 100 100
3 99
3 99
ans:
300
"""

"""
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
ans:
10000000001
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
### MAIN ###
        
n, m = map(int, input2().split())
a = np.array(list(map(int, input2().split())), dtype="int64")
bcs = [tuple(map(int, input2().split()))[::-1] for _ in range(m)]

a.sort()
bcs = sorted(bcs, reverse=True)

i = 0
for query in bcs:
    #print(query)
    a[i:i+query[1]] = np.maximum(a[i:i+query[1]], query[0])
    i += query[1]
    #print(a)    
print(np.sum(a))