#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { constexpr int K = 100000, B = 316; int n, k; cin >> n >> k; vector a(n); REP(i, n) cin >> a[i]; const int b = (n + B - 1) / B; vector> ls(b); bitset l(1), r(0); REP(i, n) { if (i % B == 0) ls[i / B] = l; l |= l << a[i]; } if (!l[k]) { cout << "-1\n"; return 0; } int ans = 0; r.set(k); for (int block = b - 1; block >= 0; --block) { const int start = block * B, end = min((block + 1) * B, n); vector> tmp(end - start); l = ls[block]; FOR(i, start, end) { tmp[i - start] = l; l |= l << a[i]; } for (int i = end - 1; i >= start; --i) { if ((tmp[i - start] & r).count() == 0) ++ans; r |= r >> a[i]; } } cout << ans << '\n'; return 0; }