#include #include #include #include #include #include #include #include #include #include #include #include #include namespace lib { templateusing p_queue = std::priority_queue, Comp>; templatestruct modnum; templateconstexpr T pow(T base, std::size_t p) { if (p == 0) { return T(1); } else if (p == 1) { return base; } else if (p == 2) { return base*base; } else if (p % 2 == 0) { return pow(pow(base, p / 2), 2); } else { return pow(pow(base, p / 2), 2)*base; } } templateconstexpr auto inverse(modnum const&); templatestruct modnum { static constexpr auto mod = Mod; std::uint64_t val; modnum() = default; constexpr modnum(std::uint64_t v):val(v%Mod) { } constexpr modnum& operator+=(modnum const& v) { val += v.val; val %= mod; return *this; } constexpr modnum& operator-=(modnum const& v) { val += mod - v.val; val %= mod; return *this; } constexpr modnum& operator*=(modnum const& v) { val *= v.val; val %= mod; return *this; } constexpr modnum& operator/=(modnum const& v) { return operator*=(inverse(v)); } }; templateconstexpr auto operator+(modnum lhs, modnumconst& rhs) { return lhs += rhs; } templateconstexpr auto operator+(modnum lhs, int rhs) { return lhs += rhs; } templateconstexpr auto operator+(int lhs, modnum rhs) { return rhs += lhs; } templateconstexpr auto operator-(modnum lhs, modnumconst& rhs) { return lhs -= rhs; } templateconstexpr auto operator*(modnum lhs, modnumconst& rhs) { return lhs *= rhs; } templateconstexpr auto operator*(modnum lhs, int rhs) { return lhs *= rhs; } templateconstexpr auto operator*(int lhs, modnum rhs) { return rhs *= lhs; } templateconstexpr auto operator/(modnum lhs, modnumconst& rhs) { return lhs /= rhs; } templateconstexpr auto inverse(modnumconst& base) { return pow(base, Mod - 2); } templateconstexpr auto clamp(T v) { return std::max(v, T()); } templatevoid sort(std::vector& vec) { std::sort(vec.begin(), vec.end()); } templatevoid sort(std::vector& vec, Comp&& comp) { std::sort(vec.begin(), vec.end(), std::forward(comp)); } templatevoid vector_input(std::vector& vec) { for (auto& v : vec) { std::cin >> v; } } templateauto lower_bound(std::vectorconst& vec, T v) { return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v)); } templateauto upper_bound(std::vectorconst& vec, T v) { return std::distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), v)); } struct scope_exit { std::function func; scope_exit(std::function f):func(f) { } ~scope_exit() { func(); } }; templateusing int_tag = std::integral_constant; int gcd(int x, int y) { if (x > y) { return gcd(y, x); } if (x == 0) { return y; } return gcd(y%x, x); } } void Main(); int main() { std::cin.tie(nullptr); std::cin.sync_with_stdio(false); Main(); } void Main() { int N, S; std::cin >> N >> S; std::vector data(N); for (auto& v : data) { std::cin >> v; } std::vector> prefix(1 << (N / 2)); std::vector> suffix(1 << (N - N / 2)); std::vector result; prefix[0] = std::make_pair(0, 0); suffix[0] = std::make_pair(0, 0); for (int i{}; i < N / 2; ++i) { for (int j{}; j < (1 << i); ++j) { prefix[(1 << i) + j] = std::make_pair(prefix[j].first + data[i], prefix[j].second | (1 << (N - i - 1))); } } for (int i = N / 2; i < N; ++i) { for (int j{}; j < (1 << (i - N / 2)); ++j) { suffix[(1 << (i - N / 2)) + j] = std::make_pair(suffix[j].first + data[i], suffix[j].second | (1 << (N - i - 1))); } } lib::sort(prefix); lib::sort(suffix); int start = (1 << (N - N / 2)) - 1; for (int i{}; i < (1 << N / 2); ++i) { for (; start >= 0; --start) { if (prefix[i].first + suffix[start].first <= S) { break; } } if (prefix[i].first + suffix[start].first != S) { continue; } for (int j = start; j >= 0; --j) { if (prefix[i].first + suffix[j].first != S) { break; } result.emplace_back(prefix[i].second + suffix[j].second); } } lib::sort(result, std::greater<>()); for (auto v : result) { for (int i = N - 1; i >= 0; --i) { if (v&(1 << i)) { std::cout << N - i << " "; } } std::cout << std::endl; } }