/* -*- coding: utf-8 -*- * * 1430.cc: No.1430 Coup de Coupon - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 5000; const int INF = 1 << 30; /* typedef */ /* global variables */ int ps[MAX_N]; /* subroutines */ /* main */ int main() { int n, c; scanf("%d%d", &n, &c); for (int i = 0; i < n; i++) scanf("%d", ps + i); sort(ps, ps + n); priority_queue q1, q2; for (int i = 0; i < c; i++) { int t, x; scanf("%d%d", &t, &x); if (t == 1) q1.push(x); else q2.push(x); } int sum = 0; for (int i = n - 1; i >= 0; i--) { if (q1.empty() && q2.empty()) sum += ps[i]; else { int p1 = INF, p2 = INF; if (! q1.empty()) p1 = max(ps[i] - q1.top(), 0); if (! q2.empty()) p2 = ps[i] / 100 * (100 - q2.top()); if (p1 < p2) sum += p1, q1.pop(); else sum += p2, q2.pop(); } } printf("%d\n", sum); return 0; }