#include void merge_sort(int x[], int n) { static int y[5001] = {}; if (n <= 1) return; merge_sort(&(x[0]), n/2); merge_sort(&(x[n/2]), (n+1)/2); int i, p, q; for (i = 0, p = 0, q = n/2; i < n; i++) { if (p >= n/2) y[i] = x[q++]; else if (q >= n) y[i] = x[p++]; else y[i] = (x[p] < x[q])? x[p++]: x[q++]; } for (i = 0; i < n; i++) x[i] = y[i]; } long long chmin(long long* a, long long b) { if (*a > b) *a = b; } int main() { int i, N, C, c[2] = {}, P[5001], T, X, x[2][5001]; scanf("%d %d", &N, &C); for (i = 0; i < N; i++) scanf("%d", &(P[i])); for (i = 1; i <= C; i++) { scanf("%d %d", &T, &X); T--; x[T][c[T]++] = -X; } merge_sort(P, N); merge_sort(x[0], c[0]); merge_sort(x[1], c[1]); for (i = 0; i < c[0]; i++) x[0][i] *= -1; for (i = 0; i < c[1]; i++) x[1][i] *= -1; int j, k, cur, prev; const long long sup = 1LL << 60; long long dp[2][5001] = {}; for (i = 0; i < N - C; i++) dp[0][0] += P[i]; for (j = 1; j <= c[0]; j++) dp[0][j] = sup; for (k = i, i = N - 1, cur = 1, prev = 0; i >= k; i--, cur ^= 1, prev ^= 1) { for (j = 0; j <= c[0]; j++) dp[cur][j] = (N - 1 - i - j >= 0 && N - 1 - i - j < c[1] && dp[prev][j] < sup)? dp[prev][j] + P[i] / 100 * (100 - x[1][N-1-i-j]): sup; for (j = 0; j < c[0]; j++) chmin(&(dp[cur][j+1]), dp[prev][j] + ((P[i] < x[0][j])? 0: P[i] - x[0][j])); } long long ans = sup; for (j = 0; j <= c[0]; j++) chmin(&ans, dp[prev][j]); printf("%lld\n", ans); fflush(stdout); return 0; }