#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for(int i = 0; i < (n); i++) #define per(i, n) for(int i = (n) - 1; i >= 0; i--) using ll = long long; #define vi vector #define vvi vector #define vl vector #define pii pair #define pll pair #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mod 1000000007 using namespace std; template bool chmax(T &a, const U &b){ return a < b ? (a = b, 1) : 0; } template bool chmin(T &a, const U &b){ return a > b ? (a = b, 1) : 0; } int main(){ int n,K; cin >> n >> K; vi a(n); rep(i, n) cin >> a[i]; vi dp(K + 1), cnt(K + 1); dp[0] = 1; rep(i, n){ cnt[a[i]]++; for(int j = K - a[i]; j >= 0; j--) dp[j+a[i]] += dp[j]; } if(!dp[K]){ cout << "-1\n"; return 0; } int ans = 0; rep(i, K + 1){ ll v = (ll)cnt[i] * i; if(!v || v > K) continue; vi t = dp; rep(j, K+1-v) t[j+v] -= t[j]; if(!t[K]) ans += cnt[i]; } cout << ans << "\n"; }