using System; using System.Collections.Generic; using System.Linq; class B { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static (int t, int x) Read2() { var a = Read(); return (a[0], a[1]); } static void Main() => Console.WriteLine(Solve()); static object Solve() { var (n, cc) = Read2(); var ps = Array.ConvertAll(new bool[n], _ => int.Parse(Console.ReadLine())); var cs = Array.ConvertAll(new bool[cc], _ => Read2()); ps = ps.OrderBy(x => -x).ToArray(); var q1 = new Queue(cs.Where(c => c.t == 1).Select(c => c.x).OrderBy(x => -x)); var q2 = new Queue(cs.Where(c => c.t == 2).Select(c => c.x).OrderBy(x => -x)); var r = 0; foreach (var p in ps) { var (t1, t2) = (1 << 30, 1 << 30); if (q1.Any()) t1 = Math.Max(0, p - q1.Peek()); if (q2.Any()) t2 = p - p / 100 * q2.Peek(); if (t1 < t2) { q1.Dequeue(); r += t1; } else if (t1 > t2) { q2.Dequeue(); r += t2; } else { if (t1 == 1 << 30) { r += p; } else { q2.Dequeue(); r += t2; } } } return r; } }