#include #include #include #include #include #include #include using namespace std; const int n_max = 31; const int n_mid = 16; int main() { int n, s; cin >> n >> s; vector p(n, 0); for (int i = 0; i < n; i++) { cin >> p[i]; } vector< map > > maps(2); // (price, vector)恮vector maps[0][0] = vector(1,0); maps[1][0] = vector(1,0); for (int idx = 0; idx < 2; idx++) { int n_bit, offset; if (idx == 0) { n_bit = min(n, n_mid); offset = 0; } else { n_bit = max(0, n - n_mid); offset = n_mid; } for (int i = 1; i < (1 << n_bit); i++) { int total = 0; for (int j = 0; j < n_bit; j++) { if (i & (1 << j)) { total += p[j + offset]; } } if (total > s) { continue; } if (maps[idx].count(total)) { maps[idx][total].push_back(i); } else { maps[idx][total] = vector(1, i); } } } vector ans; for (auto it = maps[0].begin(); it != maps[0].end(); it++) { int rest = s - it->first; if (maps[1].count(rest)) { for (int i = 0; i < it->second.size(); i++) { for (int j = 0; j < maps[1][rest].size(); j++) { ans.push_back(it->second[i] | (maps[1][rest][j] << n_mid) ); } } } } for (int i = 0; i < ans.size(); i++) { int tmp = 0; // cout << static_cast< bitset >(ans[i]) << endl; for (int j = 0; j < n_max; j++) { if (ans[i] & (1 << j)) { tmp |= 1 << (n_max - j - 1); } } ans[i] = tmp; // cout << static_cast< bitset >(tmp) << endl; } sort(ans.begin(), ans.end(), greater()); for (int i = 0; i < ans.size(); i++) { bool first = true; for (int j = n_max - 1; j >= 0; j--) { if (ans[i] & (1 << j)) { if (!first) { printf(" "); } printf("%d", n_max - j); first = false; } } printf("\n"); } return 0; }