Submission #1099374

#TimeUsernameProblemLanguageResultExecution timeMemory
1099374vjudge1Kitchen (BOI19_kitchen)C++17
100 / 100
73 ms100504 KiB
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int MaxN = 3e2 + 5; int n, m, k; int a[MaxN]; int b[MaxN]; void Inp() { cin >> n >> m >> k; for (int x = 1; x <= n; x++) { cin >> a[x]; } for (int x = 1; x <= m; x++) { cin >> b[x]; } } int F[MaxN][MaxN * MaxN + 5]; void Exc() { int suma = 0, sumb = 0; for (int x = 1; x <= n; x++) { suma += a[x]; if (a[x] < k || m < k) { cout << "Impossible"; return; } } for (int x = 1; x <= m; x++) { sumb += b[x]; } for (int x = 0; x <= m; x++) { for (int y = 0; y <= sumb; y++) { F[x][y] = -1; } } F[0][0] = 0; for (int x = 1; x <= m; x++) { for (int y = 0; y < b[x]; y++) { if (F[x - 1][y] != -1) { F[x][y] = F[x - 1][y]; } } for (int y = b[x]; y <= sumb; y++) { if (F[x - 1][y] != -1) { F[x][y] = F[x - 1][y]; } if (F[x - 1][y - b[x]] != -1) { F[x][y] = max(F[x][y], F[x - 1][y - b[x]] + min(b[x], n)); } } } for (int x = suma; x <= sumb; x++) { if (F[m][x] >= n * k) { cout << x - suma; return; } } cout << "Impossible"; } int main() { //freopen("G.INP", "r", stdin); //freopen("G.OUT", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); int test = 1; //cin >> test; for (int x = 1; x <= test; x++) { Inp(); Exc(); } return 0; }
#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...