// Bismi Allah
#include "bits/stdc++.h"
using namespace std;
// #define int long long
int dp[(int)10000][10000];
signed main () {
int n, m, k;
cin >> n >> m >> k;
int meal[n], chef[m], mealCopy[n];
for(int i = 0; i < n; i ++) cin >> meal[i];
for(int i = 0; i < m; i ++) cin >> chef[i];
if(*min_element(meal, meal + n) < k) {
cout << "Impossible";
return 0;
}
if(m < k) {
cout << "Impossible";
return 0;
}
// if(k == 1) {
// int szdp = accumulate(meal, meal + n, 0LL);
// vector <int> dp((int)1e6, 0);
// dp[0] = 1;
// for(auto j : chef) {
// for(int i = (int)1e6-1; i >= 0; i --) {
// if(!dp[i]) continue;
// dp[i+j] = 1;
// }
// }
// int mn = 1e9;
// for(int i = 0; i < dp.size(); i ++) {
// if(dp[i] == 0) continue;
// if(i < szdp) continue;
// mn = min(mn, i-szdp);
// }
// if(mn == 1e9) cout << "Impossible\n";
// else
// cout << mn << "\n";
// return 0;
// }
// if(*max_element(meal, meal + n) > 40 || *max_element(chef, chef + m) > 40){
// int ans = 1e9;
// for(int mask = 0; mask < (1 << m); mask ++) {
// if(__builtin_popcount(mask) < k) continue;
// vector <int> cook;
// for(int i = 0; i < m; i ++) {
// if(mask & (1 << i)) {
// cook.push_back(chef[i]);
// }
// }
// if(accumulate(cook.begin(), cook.end(), 0LL) < accumulate(meal, meal + n, 0LL)) continue;
// int cnt = 0, other = 0;
// for(int i = 0; i < cook.size(); i ++) {
// if(cook[i] >= n) cnt ++;
// else {
// other += cook[i];
// }
// }
// cnt += (other / n);
// if(cnt >= k)
// ans = min(ans, accumulate(cook.begin(), cook.end(), 0LL) - accumulate(meal, meal + n, 0LL));
// }
// if(ans == 1e9) cout << "Impossible";
// else
// cout << ans;
// return 0;
// }
int szdp = accumulate(meal, meal + n, 0);
dp[0][0]= 1;
for(auto coin : chef) {
for(int i = (int)1e5-1; i >= 0; i --) {
for(int rezerv = 0; rezerv < 1000; rezerv ++) {
if(dp[i][rezerv]) {
dp[i+coin][rezerv + min(n, coin)] = 1;
}
}
}
}
int ans = 1e9;
for(int i = szdp; i < (int)1e5; i ++) {
for(int rezerv = n*k; rezerv < 1000; rezerv ++) {
if(dp[i][rezerv])
ans = min(ans, i-szdp);
}
}
if(ans == 1e9) cout << "Impossible";
else
cout << ans;
return 0;
}
Compilation message
kitchen.cpp: In function 'int main()':
kitchen.cpp:13:24: warning: unused variable 'mealCopy' [-Wunused-variable]
13 | int meal[n], chef[m], mealCopy[n];
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |