#include <bits/stdc++.h>
using namespace std;
const int N = 10005, M = 505, oo = 1e9 + 7;
void mini(int &X, int Y) {
if (X > Y) X = Y;
}
void maxi(int &X, int Y) {
if (X < Y) X = Y;
}
int n, m, a[N];
int dp[N << 1];
signed main(void) {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n, greater<int>());
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
dp[0] = 0;
for (int i = 1; i <= n + 10000; i++) dp[i] = oo;
for (int j = 1, c, e; j <= m; j++) {
cin >> c >> e;
for (int i = n + 10000; i >= c; i--) {
mini(dp[i], dp[i - c] + e);
}
}
for (int i = n + 9999; i; i--) mini(dp[i], dp[i + 1]);
int ans = 0;
for (int i = 1; i <= n; i++) maxi(ans, a[i] - dp[i]);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |