Submission #39683

#TimeUsernameProblemLanguageResultExecution timeMemory
3968314kg만두 팔기 (JOI14_manju)C++11
100 / 100
163 ms25660 KiB
#include <stdio.h> #include <algorithm> #define min2(x,y) (x<y?x:y) using namespace std; struct BOX { int cnt, value; } box[501]; int n, m, in[10001], p[10001]; int dp[501][10001]; bool check[501][10001]; int max2(int x, int y) { return x > y ? x : y; } int f(int x, int y) { if (x == 0 || y == 0) return 0; if (!check[x][y]) { check[x][y] = true; int cnt = min2(y, box[x].cnt); dp[x][y] = max2(f(x - 1, y), f(x - 1, y - cnt) + p[y] - p[y - cnt] - box[x].value); } return dp[x][y]; } int main() { scanf("%d %d", &m, &n); for (int i = 1; i <= m; i++) scanf("%d", &in[i]); for (int i = 1; i <= n; i++) scanf("%d %d", &box[i].cnt, &box[i].value); sort(in + 1, in + m + 1); for (int i = 1; i <= m; i++) p[i] = p[i - 1] + in[i]; printf("%d", f(n, m)); }

Compilation message (stderr)

t2.cpp: In function 'int main()':
t2.cpp:23:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &m, &n);
                        ^
t2.cpp:24:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= m; i++) scanf("%d", &in[i]);
                                                  ^
t2.cpp:25:73: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d %d", &box[i].cnt, &box[i].value);
                                                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...