using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static int[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => int.Parse(ReadLine())).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var p = LList(n); var map = NArr(m); var a = new List(); var b = new List(); foreach (var coup in map) { if (coup[0] == 1) a.Add(coup[1]); else b.Add(coup[1]); } Array.Sort(p, (l, r) => r.CompareTo(l)); a.Sort((l, r) => r.CompareTo(l)); b.Sort((l, r) => r.CompareTo(l)); var dp = new long[a.Count + 1][]; for (var i = 0; i < dp.Length; ++i) dp[i] = new long[b.Count + 1]; for (var i = 0; i < dp.Length; ++i) for (var j = 0; j < dp[i].Length; ++j) { if (i + 1 < dp.Length && i + j < n) dp[i + 1][j] = Math.Max(dp[i + 1][j], dp[i][j] + Math.Min(p[i + j], a[i])); if (j + 1 < dp[i].Length && i + j < n) dp[i][j + 1] = Math.Max(dp[i][j + 1], dp[i][j] + p[i + j] * b[j] / 100); } var ans = 0L; foreach (var pi in p) ans += pi; var max = 0L; foreach (var di in dp) foreach (var dij in di) max = Math.Max(max, dij); WriteLine(ans - max); } }