# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20840 | kdh9949 | 만두 팔기 (JOI14_manju) | C++14 | 39 ms | 41536 KiB |
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 <bits/stdc++.h>
using namespace std;
int n, m, a[10010], b[505], c[505], dp[505][20010], ans;
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(int i = 1; i <= m; i++) scanf("%d%d", c + i, b + i);
fill(dp[0] + 1, dp[0] + n + 10001, 1e9);
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n + 10000; j++){
dp[i][j] = dp[i - 1][j];
if(j >= c[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - c[i]] + b[i]);
}
}
for(int i = n + 9999; i >= 1; i--) dp[m][i] = min(dp[m][i], dp[m][i + 1]);
sort(a + 1, a + n + 1, greater<int>());
for(int i = 1; i <= n; i++){
a[i] += a[i - 1];
ans = max(ans, a[i] - dp[m][i]);
}
printf("%d\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |