#include <iostream>
using namespace std;
int main() {
int n;
int g[5] = {1,2,4,8,16};
int arr[5];
for (int i = 0;i < 5;i++) {
cin >> arr[i];
}
cin >> n;
int i = 4;
int cnt = 0;
while (true) {
if (n < g[i] || arr[i] == 0){
i -= 1;
continue;
}
if (n == 0) {
cout << cnt;
return 0;
}
if (arr[0] == 0) break;
n -= g[i];
arr[i] -= 1;
cnt++;
}
cout << "impossible";
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: