#pragma GCC optimize ("O2") #pragma GCC target ("avx2") #include //#include //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int N, C, P[5000], A[5000], B[5000], a, b; int dp[5001][5001]; int keisan(int i, int j) { if (dp[i][j] != -1) return dp[i][j]; if (i == 0) return dp[i][j] = 0; int ret = 0; int k = i - j; if (j <= a && j > 0) { chmax(ret, keisan(i - 1, j - 1) + min(A[j - 1], P[i - 1])); } if (k <= b && k > 0) { chmax(ret, keisan(i - 1, j) + (B[k - 1] * P[i - 1] / 100)); } return dp[i][j] = ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> C; rep(i, N) cin >> P[i]; sort(P, P + N); reverse(P, P + N); rep(i, C) { int t, x; cin >> t >> x; if (t == 1) { A[a++] = x; } else B[b++] = x; } sort(A, A + a); reverse(A, A + a); sort(B, B + b); reverse(B, B + b); rep(i, N + 1) rep(j, C + 1) dp[i][j] = -1; int kotae = 0; int ab = min(C, N); rep(i, a + 1) { int j = ab - i; if (j >= 0 && j <= b) { chmax(kotae, keisan(ab, i)); } } rep(i, N) kotae -= P[i]; co(-kotae); Would you please return 0; }