Language: C++

/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/
#pragma GCC optimize('Ofast')
// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }

inline template<typename T> void fastin(T &num) {
  //bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
//  if (c == '-') {
//    negative = true;
//    c = getchar_unlocked();
//  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  //if (negative) num *= -1;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}

int main(){
  //ios_base::sync_with_stdio(false);
  //cin.tie(nullptr);

  int n, m; fastin(n); fastin(m);
  priority_queue<int64, vector<int64>, greater<int64>> a;
  for (int i = 0; i < n; ++i) {
    int64 x; fastin(x);
    a.push(x);
  }

  for (int i = 0; i < m; ++i) {
    int64 b, c; cin >> b >> c;
    while (a.top() < c && b > 0) {
      a.pop(); --b; a.push(c);
      //assert((int) a.size() == n);
    }
  }

  int64 ans = 0;
  while (!a.empty()) {
    ans += a.top(); a.pop();
  }

  fastout(ans);

  return 0;
}

Compiler output:
a.cc:6:22: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
    6 | #pragma GCC optimize('Ofast')
      |                      ^~~~~~~
a.cc:6:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
a.cc:52:16: error: expected unqualified-id before '<' token
   52 | inline template<typename T> void fastin(T &num) {
      |                ^
a.cc:63:2: error: expected ';' before 'template'
   63 | }
      |  ^
      |  ;
   64 | 
   65 | template<typename T> void fastout(T &n) {
      | ~~~~~~~~
a.cc: In function 'int main()':
a.cc:93:13: error: 'fastin' was not declared in this scope; did you mean 'asin'?
   93 |   int n, m; fastin(n); fastin(m);
      |             ^~~~~~
      |             asin
a.cc:113:3: error: 'fastout' was not declared in this scope
  113 |   fastout(ans);
      |   ^~~~~~~