Submission #1099293

#TimeUsernameProblemLanguageResultExecution timeMemory
1099293vjudge1Kitchen (BOI19_kitchen)C++17
100 / 100
104 ms202956 KiB
#include<bits/stdc++.h> #define ll long long #define task "" using namespace std; const ll maxn = 302, LG = 21, mod = 998244353, inf = 1e18; ll n, m, k, a[maxn], b[maxn], req = 0, tot = 0, dp[maxn][maxn*maxn]; int main () { //freopen(task".INP", "r", stdin); //freopen(task".OUT", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; req += a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; tot += b[i]; } if (m < k || tot < req) { cout << "Impossible"; return 0; } for (int i = 1; i <= n; i++) if (a[i] < k) { cout << "Impossible"; return 0; } for (int i = 0; i <= m; i++) for (int j = 0; j <= tot; j++) dp[i][j] = -1; dp[0][0] = 0; for (int i = 0; i < m; i++) for (int j = 0; j <= tot; j++) { if (dp[i][j] == -1) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j + b[i + 1] <= tot) dp[i + 1][j + b[i + 1]] = max(dp[i + 1][j + b[i + 1]], dp[i][j] + min(b[i + 1], n)); } for (int i = req; i <= tot; i++) if (dp[m][i] >= n*k) { cout << i - req; return 0; } cout << "Impossible"; }
#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...