#include #include using namespace std; using namespace atcoder; #define MOD 1000000007 #define MOD9 998244353 #define pb push_back #define yes "Yes" #define no "No" #define takah "Takahashi" #define aoki "Aoki" #define ALL(x) (x).begin(), (x).end() template bool chmax(T &x, const T &y){if (x < y) {x = y; return true;} return false;} template bool chmin(T &x, const T &y){if (x > y) {x = y; return true;} return false;} template void print(T x){cout << x << endl;} int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int N, C; cin >> N >> C; vector P(N); for (int i = 0; i < N; i++) cin >> P[i]; vector> Cs(C, vector(2)); for (int i = 0; i < C; i++){ cin >> Cs[i][0] >> Cs[i][1]; } for (int i = 0; i < min(0, N - C); i++){ Cs.pb({1, 0}); C++; } mcf_graph graph(N + C + 2); int S = N + C; int T = N + C + 1; for (int i = 0; i < N; i++){ graph.add_edge(S, i, 1, 0); for (int j = 0; j < C; j++){ int price; if (Cs[j][0] == 1){ price = max(P[i] - Cs[j][1], 0); } else { price = P[i] * (100 - Cs[j][1]) / 100; } graph.add_edge(i, j + N, 1, price); } } for (int j = 0; j < C; j++){ graph.add_edge(j + N, T, 1, 0); } cout << graph.flow(S, T).second << endl; }