Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    b_list = []
    c_list = []
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for j in range(m):
        b, c = map(int, input().split())
        a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    a_list.sort(reverse=True)
    print(sum(a_list[:n]))

solve()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
import numpy as np
from collections import defaultdict
d = defaultdict(int)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    # b_list = []
    # c_list = []
    n, m = map(int, input().split())
    d = defaultdict(int)
    a_list = list(map(int, input().split()))

    for a in a_list:
        d[a] += 1

    for j in range(m):
        b, c = map(int, input().split())
        d[c] += b
        # a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    #print(d)
    current_n = 0
    sum = 0
    for k in sorted(d.keys(), reverse=True):
        sum += min(d[k], n - current_n) * k
        current_n += d[k]
        if current_n >= n:
            break
    print(sum)
    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    # a_list.sort(reverse=True)
    # print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]
    #
    # print(np.sum(a))
solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    b_list = []
    c_list = []
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for j in range(m):
        b, c = map(int, input().split())
        b_list.append(b)
        c_list.append(c)
    #print(a_list)

    for j in range(m):
        for bj in range(b_list[j]):
            a_list.append(c_list[j])

    a_list.sort(reverse=True)
    print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]

    # print(np.sum(a))
solve()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
import numpy as np
from collections import defaultdict
d = defaultdict(int)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    # b_list = []
    # c_list = []
    n, m = map(int, input().split())
    d = defaultdict(int)
    a_list = list(map(int, input().split()))

    for a in a_list:
        d[a] += 1

    for j in range(m):
        b, c = map(int, input().split())
        d[c] += b
        # a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    #print(d)
    current_n = 0
    sum = 0
    for k in sorted(d.keys(), reverse=True):
        sum += min(d[k], n - current_n) * k
        current_n += d[k]
        if current_n >= n:
            break
    print(sum)
    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    # a_list.sort(reverse=True)
    # print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]
    #
    # print(np.sum(a))
solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    b_list = []
    c_list = []
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for j in range(m):
        b, c = map(int, input().split())
        b_list.append(b)
        c_list.append(c)
    #print(a_list)

    a = np.array(a_list, dtype=np.int64)

    for j in range(m):
        a.sort()
        # print(a)
        # print(c_list[j])
        to_index = min(b_list[j], sum(a < c_list[j]))
        a[:to_index] = c_list[j]
        # print(a)
        # print("")

    print(np.sum(a))
solve()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
import numpy as np
from collections import defaultdict
d = defaultdict(int)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    # b_list = []
    # c_list = []
    n, m = map(int, input().split())
    d = defaultdict(int)
    a_list = list(map(int, input().split()))

    for a in a_list:
        d[a] += 1

    for j in range(m):
        b, c = map(int, input().split())
        d[c] += b
        # a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    #print(d)
    current_n = 0
    sum = 0
    for k in sorted(d.keys(), reverse=True):
        sum += min(d[k], n - current_n) * k
        current_n += d[k]
        if current_n >= n:
            break
    print(sum)
    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    # a_list.sort(reverse=True)
    # print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]
    #
    # print(np.sum(a))
solve()