#include // clang-format off using namespace std;constexpr int INF=1001001001;constexpr long long INFll=1001001001001001001;namespace viewer{template string f(T i){string s=(i==INF||i==INFll?"inf":to_string(i));s=string(max(0,3-int(s.size())),' ')+s;return s;} templateauto v(T&x,string end)->decltype(cerr<void v(const pair&p,string end="\n"){cerr<<"(";v(p.first,", ");v(p.second,")"+end);}templatevoid v(const tuple&t,string end="\n"){auto[a,b]=t;cerr<<"(";v(a,", ");v(b,")"+end);}templatevoid v(const tuple&t,string end="\n"){auto[a,b,c]=t;cerr<<"(";v(a,", ");v(b,", ");v(c,")"+end);}templatevoid v(const tuple&t,string end="\n"){auto[a,b,c,d]=t;cerr<<"(";v(a,", ");v(b,", ");v(c,", ");v(d,")"+end);} templatevoid v(const vector&vx,string);templateauto ve(int,const vector&vx)->decltype(cerr<auto ve(bool,const vector &vx){cerr << "{\n";for(const T&x:vx)cerr<<" ",v(x,",");cerr<<"}\n";}templatevoid v(const vector&vx, string){ve(0,vx);}templatevoid v(const deque&s,string e){vectorz(s.begin(),s.end());v(z,e);} templatevoid v(const set&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const multiset&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const unordered_set&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const priority_queue&p,string e){priority_queueq=p;vectorz;while(!q.empty()){z.push_back(q.top());q.pop();}v(z,e);} templatevoid v(const map&m,string e){cerr<<"{"<<(m.empty()?"":"\n");for(const auto&kv:m){cerr<<" [";v(kv.first,"");cerr<<"] : ";v(kv.second,"");cerr<<"\n";}cerr<<"}"+e;}templatevoid _view(int n,string s,T&var){cerr<<"\033[1;32m"<void grid(T _){}void grid(const vector>&vvb){cerr<<"\n";for(const vector&vb:vvb){for(const bool&b:vb)cerr<<(b?".":"#");cerr<<"\n";}} void _debug(int,string){}templatevoid _debug(int n,string S,H h,T... t){int i=0,cnt=0;for(;iap;mint re=a;for(long long r=1;r> N >> K; vector As(N); for (int i = 0; i < N; i++) { cin >> As[i]; } vector> dp1(N + 1, vector(K + 1, false)); dp1[0][0] = true; for (int n = 1; n <= N; n++) { for (int k = 0; k <= K; k++) { dp1[n][k] = dp1[n - 1][k] || (k - As[n - 1] >= 0 && dp1[n - 1][k - As[n - 1]]); } } vector> dp2(N + 1, vector(K + 1, false)); dp2[N][0] = true; for (int n = N - 1; n >= 0; n--) { for (int k = 0; k <= K; k++) { dp2[n][k] = dp2[n + 1][k] || (k - As[n] >= 0 && dp2[n + 1][k - As[n]]); } } // debug(dp1); if (!dp1[N][K]) { cout << -1 << endl; return 0; } assert(dp2[0][K]); int ans = 0; for (int i = 0; i < N; i++) { bool ok = true; for (int k = 0; k < K; k++) { if (dp1[i][k] && dp2[N - i - 1][K - k]) { ok = false; break; } } if (ok) { ans++; } } cout << ans << endl; return 0; }