Submission #667170

#TimeUsernameProblemLanguageResultExecution timeMemory
667170KahouKitchen (BOI19_kitchen)C++14
9 / 100
4 ms212 KiB
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 305; int n, m, k, a[N], b[N], c[N]; vector<int> vc; void solve() { cin >> n >> m >> k; int sm = 0; bool flg = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; sm += a[i]; flg = flg&&(a[i] >= k); } for (int i = 1; i <= m; i++) { cin >> b[i]; } if (!flg) { cout << "Impossible" << endl; return; } int ans = 1e9; for (int mask = 0; mask < (1<<m); mask++) { vc.clear(); int sm2 = 0; for (int i = 1; i <= m; i++) { if (mask>>(i-1)&1) { vc.push_back(b[i]); sm2 += b[i]; } } if (sm2 < sm) continue; sort(vc.begin(), vc.end()); int tmp = 0; int t = 0; for (int i = 0; i <= (int)vc.size()-k; i++) { c[i] = vc[i] - tmp; t += c[i]; tmp += c[i]; if (i >= k-1) tmp -= c[i-k+1]; } if (t >= n) ans = min(ans, sm2-sm); } if (ans >= 1e9) { cout << "Impossible" << endl; return; } cout << ans << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); 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...