#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main() { constexpr int MAX_K = 1000; int n, k; std::cin >> n >> k; std::vector number(n); for (auto& a : number) { std::cin >> a; } std::vector> forward(n); forward[0].set(0, true); for (auto i = 1; i < n; ++i) { forward[i] = (forward[i - 1] << number[i - 1]) | forward[i - 1]; } if (forward.back().test(k) || forward.back().test(k - number.back())) { int result{ 0 }; std::bitset backward; backward.set(k, true); for (int i = n - 1; i >= 0; --i) { const auto a = number[i]; if ((backward & forward[i]).none()) { result += 1; } backward |= backward >> a; } std::cout << result << '\n'; } else { std::cout << "-1\n"; } }