/* -*- coding: utf-8 -*- * * 1861.cc: No.1861 Required Number - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 10000; const int MAX_K = 1000; /* typedef */ /* global variables */ int as[MAX_N]; bool dp0[MAX_N + 1][MAX_K + 1], dp1[MAX_N + 1][MAX_K + 1]; /* subroutines */ /* main */ int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", as + i); dp0[0][0] = true; for (int i = 0; i < n; i++) { copy(dp0[i], dp0[i] + k + 1, dp0[i + 1]); for (int j = k - as[i]; j >= 0; j--) if (dp0[i][j]) dp0[i + 1][j + as[i]] = true; } if (! dp0[n][k]) { puts("-1"); return 0; } dp1[n][0] = true; for (int i = n - 1; i >= 0; i--) { copy(dp1[i + 1], dp1[i + 1] + k + 1, dp1[i]); for (int j = k - as[i]; j >= 0; j--) if (dp1[i + 1][j]) dp1[i][j + as[i]] = true; } int cnt = 0; for (int i = 0; i < n; i++) { bool found = false; for (int j = 0; ! found && j <= k; j++) found = (dp0[i][j] && dp1[i + 1][k - j]); if (! found) cnt++; } printf("%d\n", cnt); return 0; }