This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
using namespace std;
const int MAX_M = 1e4;
int m, n,a[10000],dp[MAX_M*2+1],res;
int main() {
scanf("%d %d", &m, &n);
for (int i = 0; i < m; i++) scanf("%d", &a[i]);
sort(a, a + m);
fill(dp + 1, dp + MAX_M*2+1,1e9);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
for (int j = MAX_M * 2; j >= x; j--)
dp[j] = min(dp[j], dp[j - x] + y);
}
for (int i = MAX_M * 2; i; i--) dp[i - 1] = min(dp[i - 1], dp[i]);
int s = 0;
for (int i = m - 1; i >= 0; i--) {
s += a[i];
res = max(res, s - dp[m-i]);
}
printf("%d", res);
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... |