#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 it0 = maps[0].begin(); it0 != maps[0].end(); it0++) { for (auto it1 = maps[1].begin(); it1 != maps[1].end(); it1++) { if(it0->first + it1->first == s) { for (int i = 0; i < it0->second.size(); i++) { for (int j = 0; j < it1->second.size(); j++) { ans.push_back(it0->second[i] | (it1->second[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++) { for (int j = n_max - 1; j >= 0; j--) { if (ans[i] & (1 << j)) { printf("%2d ", n_max - j); } } printf("\n"); } return 0; }