Language: C++

using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);

        var aa = new PriorityQueue<int>(n);

        spl = input.ReadLine().Split(' ');
        for (int i=0; i<n; i++) {
            aa.Push(int.Parse(spl[i]));
        }

        var bbcc = new List<BC>();
        for(int i=0; i<m; i++) {
            var bc = new BC();
            spl = input.ReadLine().Split(' ');
            bc.b = int.Parse(spl[0]);
            bc.c = int.Parse(spl[1]);
            bbcc.Add(bc);
        }

        bbcc.Sort((a,b) => { return b.b - a.b; });

        foreach(var bc in bbcc) {
            if (bc.c <= aa.Peek()) break;

            for(int j=0; j<bc.b; j++) {
                var a = aa.Pop();
                if (bc.c <= a) {
                    aa.Push(a);
                    break;
                } else {
                    aa.Push(bc.c);
                }
            }
        }

        var sum = 0L;
        foreach(var a in aa) {
            sum += a;
        }

        return sum;
    }

    class BC
    {
        public int b;
        public int c;
    }

    //コピペ
    public class PriorityQueue<T> where T : IComparable
    {
        private IComparer<T> _comparer = null;
        private int _type = 0;

        private T[] _heap;
        private int _sz = 0;

        private int _count = 0;

        /// <summary>
        /// Priority Queue with custom comparer
        /// </summary>
        public PriorityQueue(int maxSize, IComparer<T> comparer) {
            _heap = new T[maxSize];
            _comparer = comparer;
        }

        /// <summary>
        /// Priority queue
        /// </summary>
        /// <param name="maxSize">max size</param>
        /// <param name="type">0: asc, 1:desc</param>
        public PriorityQueue(int maxSize, int type = 0) {
            _heap = new T[maxSize];
            _type = type;
        }

        private int Compare(T x, T y) {
            if (_comparer != null) return _comparer.Compare(x, y);
            return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
        }

        public void Push(T x) {
            _count++;

            //node number
            var i = _sz++;

            while (i > 0) {
                //parent node number
                var p = (i - 1) / 2;

                if (Compare(_heap[p], x) <= 0) break;

                _heap[i] = _heap[p];
                i = p;
            }

            _heap[i] = x;
        }

        public T Pop() {
            _count--;

            T ret = _heap[0];
            T x = _heap[--_sz];

            int i = 0;
            while (i * 2 + 1 < _sz) {
                //children
                int a = i * 2 + 1;
                int b = i * 2 + 2;

                if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b;

                if (Compare(_heap[a], x) >= 0) break;

                _heap[i] = _heap[a];
                i = a;
            }

            _heap[i] = x;

            return ret;
        }

        public int Count() {
            return _count;
        }

        public T Peek() {
            return _heap[0];
        }

        public bool Contains(T x) {
            for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true;
            return false;
        }

        public void Clear() {
            while (this.Count() > 0) this.Pop();
        }

        public IEnumerator<T> GetEnumerator() {
            var ret = new List<T>();

            while (this.Count() > 0) {
                ret.Add(this.Pop());
            }

            foreach (var r in ret) {
                this.Push(r);
                yield return r;
            }
        }

        public T[] ToArray() {
            T[] array = new T[_sz];
            int i = 0;

            foreach (var r in this) {
                array[i++] = r;
            }

            return array;
        }
    }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Diagnostics;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.IO;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Text;
      |       ^~~~~~
a.cc:5:7: error: expected nested-name-specifier before 'System'
    5 | using System.Linq;
      |       ^~~~~~
a.cc:6:7: error: expected nested-name-specifier before 'System'
    6 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:10:22: error: 'string' has not been declared
   10 |     static void Main(string[] args) {
      |                      ^~~~~~
a.cc:10:31: error: expected ',' or '...' before 'args'
   10 |     static void Main(string[] args) {
      |                               ^~~~
a.cc:20:12: error: 'object' does not name a type
   20 |     static object process(TextReader input) {
      |            ^~~~~~
a.cc:67:15: error: expected ':' before 'int'
   67 |         public int b;
      |               ^~~~
      |               :
a.cc:68:15: error: expected ':' before 'int'
   68 |         public int c;
      |               ^~~~
      |               :
a.cc:69:6: error: expected ';' after class definition
   69 |     }
      |      ^
      |      ;
a.cc:72:11: error: expected ':' before 'class'
   72 |     public class PriorityQueue<T> where T : IComparable
      |           ^~~~~~
      |           :
a.cc:72:18: error: 'PriorityQueue' is not a class template
   72 |     public class PriorityQueue<T> where T : IComparable
      |                  ^~~~~~~~~~~~~
a.cc:72:32: error: 'T' was not declared in this scope
   72 |     public class PriorityQueue<T> where T : IComparable
      |                                ^
a.cc:72:35: error: field 'where' has incomplete type 'PriorityQueue'
   72 |     public class PriorityQueue<T> where T : IComparable
      |                                   ^~~~~
a.cc:72:18: note: forward declaration of 'class PriorityQueue'
   72 |     public class PriorityQueue<T> where T : IComparable
      |                  ^~~~~~~~~~~~~
a.cc:72:35: error: expected ';' at end of member declaration
   72 |     public class PriorityQueue<T> where T : IComparable
      |                                   ^~~~~
      |                                        ;
a.cc:72:41: error: 'T' does not name a type
   72 |     public class PriorityQueue<T> where T : IComparable
      |                                         ^
a.cc:190:2: error: expected ';' after class definition
  190 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main(int*)':
a.cc:15:9: error: 'object' was not declared in this scope
   15 |         object ret = process(new StreamReader(Console.OpenStandardInput()));
      |         ^~~~~~
a.cc:16:9: error: 'Console' was not declared in this scope
   16 |         Console.WriteLine(ret);
      |         ^~~~~~~
a.cc:16:27: error: 'ret' was not declared in this scope
   16 |         Console.WriteLine(ret);
      |                           ^~~