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

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

for b, c in l:
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
l = []
for _ in range(m):
    b, c = map(int, input().split())
    l += [c] * b
l = sorted(l, reverse=True)
i = 0
ans = 0
for p, q in zip(a, l):
    ans += max(p, q)
    i += 1
print(ans + sum(a[i:]))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))

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

n, m = map(int, input().split())
a = [int(i) for i in input().split()]
heapq.heapify(a)

for _ in range(m):
    b, c = map(int, input().split())
    for _ in range(b):
        p = heapq.heappop(a)
        if p < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, p)
            break

print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(i) for i in input().split()]

for _ in range(m):
    b, c = map(int, input().split())
    for _ in range(b):
        a.append(c)

s = sorted(a, reverse=True)
print(sum(s[:n]))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))

Buggy python submission (verdict: Runtime Error):
// Rustで競技プログラミングの入力をスッキリ記述するマクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BinaryHeap;

fn main() {
  input! {
      n: usize,
      m: usize,
      a: [usize; n],
      bc: [(usize, usize); m]
  };
  let mut heap = BinaryHeap::new();
  for i in a.iter() {
      heap.push(*i);
  }
  for i in bc.iter() {
      let &(b, c) = i;
      for _ in 0..b {
          heap.push(c);
      }
  }
  let mut s = 0;
  for _ in 0..n {
      s += heap.pop().unwrap();
  }
  println!("{}", s);
}


Fixed submission:
import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))

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

n, m = map(int, input().split())
a = [int(i) * -1 for i in input().split()]
heapq.heapify(a)

for _ in range(m):
    b, c = map(int, input().split())
    for _ in range(b):
        heapq.heappush(a, c * -1)

s = 0
for _ in range(n):
    s += heapq.heappop(a) * -1
print(s)

Fixed submission:
import heapq

n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []

for _ in range(m):
    b, c = map(int, input().split())
    l.append((b, c))

l = sorted(l, key=lambda x: x[1], reverse=True)

for b, c in l:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] < c:
            heapq.heappushpop(a, c)
        else:
            break

print(sum(a))