#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; ll A[5010]; ll B[5010]; ll dp[5010][5010]; int main() { int N, C; cin >> N >> C; vector P(N); for (int i = 0; i < N; ++i) { cin >> P[i]; } sort(P.begin(), P.end(), greater()); int ia = 0; int ib = 0; for (int i = 0; i < C; ++i) { ll t, x; cin >> t >> x; if (t == 1) { A[ia++] = x; } else { B[ib++] = x; } } sort(A, A + ia, greater()); sort(B, B + ib, greater()); for (int i = N; i >= 0; --i) { for (int j = 0; j < i + 1; ++j) { if (i == N) { dp[i][j] = 0; } else { ll p1 = max(0LL, P[i] - A[j]) + dp[i + 1][j + 1]; ll p2 = P[i] * (100 - B[i - j]) / 100 + dp[i + 1][j]; dp[i][j] = min(p1, p2); } } } cout << dp[0][0] << endl; return 0; }