Submission #237912

#TimeUsernameProblemLanguageResultExecution timeMemory
237912grtKitchen (BOI19_kitchen)C++17
100 / 100
366 ms101240 KiB
#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 300 + 1, INF = 1e9; int n,m,k; int s,s2; int t[nax]; int dp[nax * nax][nax]; int main() {_ cin >> n >> m >> k; bool ok = 1; for(int a,i = 1; i <= n; ++i) { cin >> a; if(a < k) ok = 0; s += a; } for(int i = 1; i <= m; ++i) { cin >> t[i]; s2 += t[i]; } if(!ok) { cout << "Impossible"; return 0; } for(int i = 0; i <= s2; ++i) { dp[i][0] = -INF; } dp[0][0] = 0; for(int i = 1; i <= m; ++i) { for(int j = 0; j <= s2; ++j) { dp[j][i] = max(dp[j][i-1], (j >= t[i] ? (dp[j - t[i]][i-1] + min(t[i], n)) : -INF)); } } int ans = INF; for(int i = s; i <= s2; ++i) { if(dp[i][m] >= k * n) { ans = i; break; } } if(ans == INF) cout << "Impossible"; else { cout << ans - s; } }
#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...