#include #include #include #include #include #include #include #include #include #include #include #include #include #define INF 1000000000 #define MOD 1000000007 #define rep(i,a,b) for(uint32 i = (a); i < (b); ++i) #define bitget(a,b) (((a) >> (b)) & 1) #define ALL(x) (x).begin(),(x).end() #define C(x) std::cout << #x << " : " << x << std::endl #define scanf scanf_s using int32 = std::int_fast32_t; using int64 = std::int_fast64_t; using uint32 = std::uint_fast32_t; using uint64 = std::uint_fast64_t; int main(void) { std::ios::sync_with_stdio(false); std::cin.tie(0); uint32 n, k, temp, ans; std::cin >> n >> k; std::vector a(n); rep(i, 0, n) std::cin >> a[i]; if (n <= 10) { std::vector b(1 << n); auto itr = b.begin(); *itr = 0; ans = k; rep(i, 0, n) { temp = 1 << i; rep(j, 0, temp) { ++itr; *itr = b[j] + a[i]; ans = std::min(ans, k - *itr); } } ans = k - ans; } else { std::vector b(1 << 10), c(1 << (n - 10)); auto itr = b.begin(); *itr = 0; rep(i, 0, 10) { temp = 1 << i; rep(j, 0, temp) { ++itr; *itr = b[j] + a[i]; } } itr = c.begin(); *itr = 0; rep(i, 10, n) { temp = 1 << (i - 10); rep(j, 0, temp) { ++itr; *itr = c[j] + a[i]; } } std::sort(c.begin(), c.end(), std::greater()); ans = 0; rep(i, 0, 1 << 10) { if (b[i] <= k) { ans = std::max(ans, b[i] + *std::lower_bound(c.begin(), c.end(), k - b[i], std::greater())); } } } std::cout << ans << std::endl; return 0; }