Submission #708960

#TimeUsernameProblemLanguageResultExecution timeMemory
708960stevancvKitchen (BOI19_kitchen)C++14
100 / 100
24 ms696 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 300 + 5; const int inf = 1e9; const int mod = 1e9 + 7; int a[N], b[N], dp[N * N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; int moze = 1; int sa, sb; sa = sb = 0; for (int i = 1; i <= n; i++) { sa += a[i]; if (a[i] < k) moze = 0; } for (int i = 1; i <= m; i++) sb += b[i]; if (moze == 0) { cout << "Impossible" << en; return 0; } for (int i = 1; i < N * N; i++) dp[i] = -inf; for (int i = 1; i <= m; i++) { for (int j = N * N - 1; j >= b[i]; j--) smax(dp[j], dp[j - b[i]] + min(b[i], n)); } for (int i = sa; i < N * N; i++) { if (dp[i] >= n * k) { cout << i - sa << en; return 0; } } cout << "Impossible" << en; 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...