Buggy python submission (verdict: Time Limit Exceeded):
N, M = 10, 3
ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
BRR = [
    [3, 10],
    [4, 30],
    [1, 4]
]

import heapq

N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        heapq.heappush(raw,ar*-1)
    for br in brr:
        for i in range(br[0]):
            heapq.heappush(raw,br[1] * -1)

    sum = 0
    for i in range(n):
        sum = sum + -1 * heapq.heappop(raw)

    print(sum)


calculate(N, M, ARR, BRR)


Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = 10, 3
ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
BRR = [
    [3, 10],
    [4, 30],
    [1, 4]
]

import heapq

N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        heapq.heappush(raw,ar)
    for br in brr:
        for i in range(br[0]):
            heapq.heappush(raw,br[1])

    while len(raw) > n:
        heapq.heappop(raw)

    print(sum(raw))


calculate(N, M, ARR, BRR)


Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]
N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    brr = sorted(brr, key=lambda x: -x[1])
    arr = sorted(arr)
    result = 0
    sIndex = 0
    for mIndex in range(m):
        br = brr[mIndex]
        kIndex = min(bisect.bisect_left(arr[sIndex:len(arr)],br[1]),br[0])
        if kIndex == 0:
            break
        result = result + kIndex*br[1]
        sIndex = sIndex + kIndex

    result = result + sum(arr[sIndex:len(arr)])

    print(result)

calculate(N, M, ARR, BRR)

Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]
N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    brr = sorted(brr, key=lambda x: -x[1])
    arr = sorted(arr)
    result = 0
    sIndex = 0
    for br in brr:
        kIndex = min(bisect.bisect_left(arr[sIndex:len(arr)],br[1]),br[0])
        if kIndex == 0:
            break
        result = result + kIndex*br[1]
        sIndex = sIndex + kIndex

    result = result + sum(arr[sIndex:len(arr)])

    print(result)

calculate(N, M, ARR, BRR)

Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]
N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    arr = np.array(arr)
    brr = sorted(brr, key=lambda x: -x[1])
    arr.sort()
    result = 0
    sIndex = 0
    for br in brr:
        kIndex = min(sum(arr[sIndex:len(arr)] < br[1]), br[0])
        if kIndex == 0:
            break
        result = result + kIndex*br[1]
        sIndex = sIndex + kIndex

    result = result + sum(arr[sIndex:len(arr)])

    print(result)


calculate(N, M, ARR, BRR)


Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]
N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    arr = np.array(arr)
    brr = sorted(brr, key=lambda x: -x[1])
    for br in brr:
        arr.sort()
        sIndex = min(sum(arr < br[1]), br[0])
        if sIndex == 0:
            break
        arr[0:sIndex] = br[1]

    print(sum(arr))


calculate(N, M, ARR, BRR)

Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
import numpy as np
def calculate(arr,sArr):

    for s in range(len(sArr)):
        arr = np.sort(arr, axis=0)

        k = bisect_right(arr,sArr[s][1])

        if k == 0:
            break

        if k >= sArr[s][0]:
            arr[:sArr[s][0]] = sArr[s][1]
        else:
            arr[:k] = sArr[s][1]

    return arr


S = input()

N = int(S.split(" ")[0])
M = int(S.split(" ")[1])

arr = [int(s) for s in input().split(" ")]
arr = np.array(arr)


arr2 = []
for i in range(M):
    tmp = [int(s) for s in input().split(" ")]
    arr2.append(tmp)

arr2 = sorted(arr2,key=lambda x:-x[1])
arr2 = np.array(arr2)


result = calculate(arr,arr2)

print(np.sum(result))


Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
import numpy as np
def calculate(arr,sArr):


    for s in range(len(sArr)):
        arr = np.sort(arr, axis=0)

        k = bisect_right(arr,sArr[s][1])

        if k >= sArr[s][0]:
            arr[:sArr[s][0]] = sArr[s][1]
        else:
            arr[:k] = sArr[s][1]

    return arr


S = input()

N = int(S.split(" ")[0])
M = int(S.split(" ")[1])

arr = [int(s) for s in input().split(" ")]
arr = np.array(arr)


arr2 = []
for i in range(M):
    tmp = [int(s) for s in input().split(" ")]
    arr2.append(tmp)

arr2 = np.array(arr2)




result = calculate(arr,arr2)

print(np.sum(result))

Fixed submission:
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
#     [3, 10],
#     [4, 30],
#     [1, 4]
# ]


N,M = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
    BRR.append(list(map(int,input().split())))

def calculate(n, m, arr, brr):
    raw = []
    for ar in arr:
        raw.append([ar, 1])
    for br in brr:
        raw.append([br[1], br[0]])

    raw = sorted(raw,key=lambda x:-x[0])
    # print(raw)

    offset = 0
    sum = 0
    for ra in raw:
        if offset + ra[1] <= n:
            sum = sum + ra[1] * ra[0]
            offset = offset + ra[1]
        else:
            sum = sum + (n - offset) * ra[0]
            offset = n
            break
    print(sum)

calculate(N, M, ARR, BRR)