Buggy python submission (verdict: Runtime Error):
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0] = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b
        heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))

Buggy python submission (verdict: Runtime Error):
import heapq
from itertools import starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = [[x, 1] for x in R()]
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0][1] -= i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b:
        heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))

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

R = lambda: map(int, input().split())
n, m = R()
a = list(R())
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    for i in range(b):
        if a[0] >= c:
            break
        heapq.heapreplace(a, c)
print(sum(a))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))

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

R = lambda: map(int, input().split())
n, m = R()
a = list(R())
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    for i in range(b):
        if a[0] >= c:
            break
        heapq.heapreplace(a, c)
print(sum(a))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))

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

R = lambda: map(int, input().split())
n, m = R()
a = sorted(R())
for _ in range(m):
    b, c = R()
    l = bisect_left(a, c)
    for i in range(b, l):
        a[i - b] = a[i]
    for i in range(max(0, l - b), l):
        a[i] = c
print(sum(a))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))

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

R = lambda: map(int, input().split())
n, m = R()
a = sorted(R())
for _ in range(m):
    b, c = R()
    l = bisect_left(a, c)
    if l > b:
        a[: l - b] = a[b : l]
    for i in range(max(0, l - b), l):
        a[i] = c
print(sum(a))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))

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

R = lambda: map(int, input().split())
n, m = R()
a = sorted(R())
for _ in range(m):
    b, c = R()
    l = bisect_left(a, c)
    if l > b:
        a[: l - b] = a[b : l]
    for i in range(max(0, l - b), l):
        a[i] = c
print(sum(a))


Fixed submission:
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))