intmain(){ cin >> n >> m; int M = (1 << n) - 1; for (int i = 1; i <= n; ++i) cin >> a[i]; memset(f, 10, sizeof f); f[0] = 1; g[0] = m; for (int S = 0; S < M; ++S) for (int i = 1; i <= n; ++i) { if (S >> i - 1 & 1) continue; int T = S | 1 << i - 1, v = a[i] > g[S]; if (f[T] > f[S] + v) { f[T] = f[S] + v; g[T] = (v ? m : g[S]) - a[i]; } elseif (f[T] == f[S] + v) g[T] = max(g[T], (v ? m : g[S]) - a[i]); } cout << f[M] << endl; return0; }