Submission #18568

#TimeUsernameProblemLanguageResultExecution timeMemory
18568choyi0521만두 팔기 (JOI14_manju)C++14
100 / 100
20 ms1200 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...