/* -*- 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 MAX_C = 5000; const int INF = 1 << 30; /* typedef */ /* global variables */ int ps[MAX_N], qs[MAX_C], rs[MAX_C]; int dp[MAX_N + 1][MAX_C + 1]; /* subroutines */ inline void setmin(int &a, int b) { if (a > b) a = b; } /* 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, greater()); int qn = 0, rn = 0; for (int i = 0; i < c; i++) { int t, x; scanf("%d%d", &t, &x); if (t == 1) qs[qn++] = x; else rs[rn++] = x; } sort(qs, qs + qn, greater()); sort(rs, rs + rn, greater()); for (int i = 0; i <= n; i++) fill(dp[i], dp[i] + qn + 1, INF); dp[0][0] = 0; for (int i = 0; i < n; i++) for (int j = 0; j <= qn; j++) { int k = i - j; if (j < qn) setmin(dp[i + 1][j + 1], dp[i][j] + max(ps[i] - qs[j], 0)); if (k < rn) setmin(dp[i + 1][j], dp[i][j] + ps[i] / 100 * (100 - rs[k])); else setmin(dp[i + 1][j], dp[i][j] + ps[i]); } int mind = INF; for (int j = 0; j <= qn; j++) setmin(mind, dp[n][j]); printf("%d\n", mind); return 0; }