Submission #783900

#TimeUsernameProblemLanguageResultExecution timeMemory
783900TheOpChickenKitchen (BOI19_kitchen)C++17
0 / 100
85 ms97192 KiB
#include <iostream> using namespace std; const long long maxN = 305, inf = 1e15; int barr[maxN], dp[maxN][555555]; int main(){ int n, m, k; cin >> n >> m >> k; int total = 0; for (int i = 0; i < n; i++){ int a; cin >> a; if (a < k){ cout << "Impossible" << endl; return 0; } total += a; } for (int i = 0; i < m; i++) cin >> barr[i]; for (int i = 0; i < m; i++){ for (int j = 0; j < maxN*maxN; j++) dp[i][j] = -inf; } dp[0][barr[0]] = min(n, barr[0]); for (int i = 1; i < m; i++){ for (int j = 0; j < maxN*maxN; j++){ dp[i][j] = dp[i-1][j]; if (barr[i] <= j){ if (dp[i-1][j-barr[i]] == -inf) continue; dp[i][j] = max(dp[i][j], dp[i-1][j-barr[i]] + min(n, barr[i])); } } } bool pos = 0; int ans; for (int i = total; i < maxN*maxN; i++){ if (dp[m-1][i] >= n*k){ pos = 1; ans = i; break; } } if (!pos) cout << "Impossible" << endl; else cout << ans-total << endl; }

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:27:50: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000' to '1530494976' [-Woverflow]
   27 |   for (int j = 0; j < maxN*maxN; j++) dp[i][j] = -inf;
      |                                                  ^~~~
#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...