Submission #724032

#TimeUsernameProblemLanguageResultExecution timeMemory
724032lovrotKitchen (BOI19_kitchen)C++17
100 / 100
37 ms1108 KiB
#include <cstdio> #include <algorithm> using namespace std; const int N = 310; const int INF = 2e9; int n, m, k, A[N], B[N]; int dp[2][N * N]; int main() { for(int i = 0; i < N * N; i++) dp[0][i] = -INF; dp[0][0] = 0; scanf("%d%d%d", &n, &m, &k); int nim = INF, sum = 0; for(int i = 0; i < n; i++) { scanf("%d", A + i); nim = min(nim, A[i]); sum += A[i]; } for(int i = 0; i < m; i++) scanf("%d", B + i); if(nim < k) { printf("Impossible\n"); return 0; } bool f = 0; int _sum = 0; for(int i = 0; i < m; i++) { f ^= 1; _sum += B[i]; for(int j = 0; j < N * N; j++) { dp[f][j] = dp[!f][j]; if(B[i] <= j) dp[f][j] = max(dp[f][j], dp[!f][j - B[i]] + min(n, B[i])); } } for(int i = sum; i < N * N; i++) if(dp[f][i] >= n * k) { printf("%d\n", i - sum); return 0; } printf("Impossible\n"); return 0; }

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
kitchen.cpp:23:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  for(int i = 0; i < m; i++) scanf("%d", B + i);
      |                             ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...