Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process = sorted(process, key=lambda x: -x[1])
    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import bisect
import sys
input = sys.stdin.readline
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = []
    min_num = min(a)
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    a.sort()
    process = sorted(process, key=lambda x: -x[1])

    for i in range(len(process)):
        index = bisect.bisect_left(a, process[i][1])
        ooo = min(index, process[i][0])
        if ooo == 0:
            continue
        else:
            a = a[ooo:]
            b.append(process[i][1] * ooo)
        if a[0] > process[i][1]:
            break

    print(sum(a)+sum(b))

if __name__ == '__main__':
    main()

Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import bisect
import sys
input = sys.stdin.readline
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = []
    min_num = min(a)
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        if array[1] > min_num:
            p_append(array)

    a.sort()
    process = sorted(process, key=lambda x: -x[1])

    for i in range(len(process)):
        index = bisect.bisect_left(a, process[i][1])
        ooo = min(index, process[i][0])
        if ooo == 0:
            continue
        else:
            a = a[ooo:]
            b.append(process[i][1] * ooo)
        if a[0] > process[i][1]:
            break

    print(sum(a)+sum(b))

if __name__ == '__main__':
    main()

Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import bisect
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = []
    min_num = min(a)
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        if array[1] > min_num:
            p_append(array)

    a.sort()
    process = sorted(process, key=lambda x: -x[1])

    for i in range(len(process)):
        index = bisect.bisect_left(a, process[i][1])
        ooo = min(index, process[i][0])
        if ooo == 0:
            continue
        else:
            a = a[ooo:]
            b.append(process[i][1] * ooo)
        if a[0] > process[i][1]:
            break

    print(sum(a)+sum(b))

if __name__ == '__main__':
    main()

Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import numpy as np
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    min_num = min(a)
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        if array[1] > min_num:
            p_append(array)


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

    for i in range(len(process)):
        index = bisect.bisect_left(a, process[i][1])
        ooo = min(index, process[i][0])
        if ooo == 0:
            continue
        else:
            a[0:ooo] = [process[i][1]]*ooo
            a.sort()
        if a[0] > process[i][1]:
            break

    print(sum(a))

if __name__ == '__main__':
    main()

Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    min_num = min(a)
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        if array[1] > min_num:
            p_append(array)


    a.sort()
    process = sorted(process, key=lambda x: -x[1])

    for i in range(len(process)):
        index = bisect.bisect_left(a, process[i][1])
        ooo = min(index, process[i][0])
        if ooo == 0:
            continue
        else:
            a = a[ooo:] + [process[i][1] for k in range(ooo)]
        if a[0] > process[i][1]:
            break

    print(sum(a))

if __name__ == '__main__':
    main()

Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
min_num = min(a)
process = []

for i in range(m):
    array = list(map(int, input().split()))
    if array[1] > min_num:
        process.append(array)


a.sort()
process = sorted(process, key=lambda x: -x[1])

for i in range(len(process)):
    index = bisect.bisect_left(a, process[i][1])
    ooo = min(index, process[i][0])
    if ooo == 0:
        continue
    else:
        a = a[ooo:] + [process[i][1] for k in range(ooo)]
    if a[0] > process[i][1]:
        break

print(sum(a))


Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
min_num = min(a)
process = []

for i in range(m):
    array = list(map(int, input().split()))
    if array[1] > min_num:
        process.append(array)


a.sort()
process = sorted(process, key=lambda x: -x[1])

for i in range(len(process)):
    index = bisect.bisect_left(a, process[i][1])
    ooo = min(index, process[i][0])
    if ooo == 0:
        continue
    else:
        a = a[ooo:] + [process[i][1] for k in range(ooo)]
    if a[0] > process[i][1]:
        break

print(sum(a))


Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
min_num = min(a)
process = []

for i in range(m):
    array = list(map(int, input().split()))
    if array[1] > min_num:
        process.append(array)


a.sort()
process = sorted(process, key=lambda x: -x[1])

for i in range(len(process)):
    index = bisect.bisect_left(a, process[i][1])
    ooo = min(index, process[i][0])
    if ooo == 0:
        continue
    else:
        a[0:ooo] = [process[i][1]]*ooo
    a.sort()
    if a[0] > process[i][1]:
        break

print(sum(a))


Fixed submission:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()