Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd

def main():
    a = dd(int)
    n, m = [int(i) for i in input().split()]
    for i in input().split():
        a[int(i)] += 1

    for _ in range(m):
        b, c = [int(i) for i in input().split()]
        for _ in range(b):
            a[c]+=1
    res = 0
    cnt = 0
    for k in sorted(list(a.keys()))[::-1]:
        v = a[k]
        if cnt + v <= n:
            num = v
        else:
            num = n - cnt
        res += num * k
        cnt += num
        if cnt >= n:
            break
    print(res) 

if __name__ == '__main__':
    main()



Fixed submission:
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    
    bc = []
    for _ in range(m):
        b, c = map(int, input().split())
        bc.append((b, c))

    total = 0
    for num, v in sorted(bc, key=lambda x: -x[1]):
        total += num
        a.extend([v]*num)
        if total >= n:
            break
    print(sum(sorted(a)[-n:]))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd

def main():
    a = dd(int)
    n, m = [int(i) for i in input().split()]
    for i in input().split():
        a[int(i)] += 1

    for _ in range(m):
        b, c = [int(i) for i in input().split()]
        for _ in range(b):
            a[c]+=1
    res = 0
    cnt = 0
    for k in sorted(list(a.keys()))[::-1]:
        v = a[k]
        if cnt + v <= n:
            num = v
        else:
            num = n - cnt
        res += num * k
        cnt += num
        if cnt >= n:
            break
    print(res) 

if __name__ == '__main__':
    main()



Fixed submission:
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    
    bc = []
    for _ in range(m):
        b, c = map(int, input().split())
        bc.append((b, c))

    total = 0
    for num, v in sorted(bc, key=lambda x: -x[1]):
        total += num
        a.extend([v]*num)
        if total >= n:
            break
    print(sum(sorted(a)[-n:]))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    for _ in range(m):
        b, c = [int(i) for i in input().split()]
        for _ in range(b):
            a.append(c)
    a = sorted(a)[-n:]
    print(sum(a))


if __name__ == '__main__':
    main()



Fixed submission:
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    
    bc = []
    for _ in range(m):
        b, c = map(int, input().split())
        bc.append((b, c))

    total = 0
    for num, v in sorted(bc, key=lambda x: -x[1]):
        total += num
        a.extend([v]*num)
        if total >= n:
            break
    print(sum(sorted(a)[-n:]))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    for _ in range(m):
        b, c = [int(i) for i in input().split()]
        a.extend([c] * b)
    a = sorted(a)[-n:]
    print(sum(a))


if __name__ == '__main__':
    main()



Fixed submission:
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    
    bc = []
    for _ in range(m):
        b, c = map(int, input().split())
        bc.append((b, c))

    total = 0
    for num, v in sorted(bc, key=lambda x: -x[1]):
        total += num
        a.extend([v]*num)
        if total >= n:
            break
    print(sum(sorted(a)[-n:]))

if __name__ == '__main__':
    main()