제출 #1320645

#제출 시각아이디문제언어결과실행 시간메모리
1320645mirasmKitchen (BOI19_kitchen)C++20
0 / 100
0 ms332 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 300 + 4; void fun () { int n, k, m; cin >> n >> m >> k; vector<int> a(n + 1), b(m + 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; if (k > m) { cout << "Impossible"; return; } vector<int> dp(N); dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = N - 1; j >= 0; j--) { if (j - a[i] < 0) break; dp[j] |= dp[j - a[i]]; } } int s = 0, ans = 1e18; for (int i = 1; i <= n; i++) s += a[i]; if (k == 1) { if (s <= b[1] && b[1] >= n) ans = min(ans, b[1] - s); if (m >= 2 && s <= b[2] && b[2] >= n) ans = min(ans, b[2] - s); if (m >= 2 && b[1] + b[2] >= n && b[1] + b[2] >= s) { for (int i = 1; i <= b[1]; i++) { if (dp[i]) { if (s - i <= b[2]) ans = min(ans, b[1] + b[2] - s); } } for (int i = 1; i <= b[2]; i++) { if (dp[i]) { if (s - i <= b[1]) ans = min(ans, b[1] + b[2] - s); } } } if (ans == 1e18) { cout << "Impossible"; return; } cout << (ans); return; } if (b[1] + b[2] >= 2 * n && b[1] + b[2] >= s) { if (b[1] >= n && b[2] >= n) { cout << b[1] + b[2] - s << endl; } else cout << "Impossible"; } else { cout << "Impossible"; } } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) fun(); 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...