// No.617 Nafmo、買い出しに行く // https://yukicoder.me/problems/no/617 // #include #include #include #include using namespace std; int calc_total(vector &items, int i); int main() { int N, K; cin >> N >> K; vector items_a; vector items_b; for (auto i = 0; i < N; ++i) { int tmp; cin >> tmp; if (i < N/2) items_a.push_back(tmp); else items_b.push_back(tmp); } vector total_a; for (auto i = 0; i < (1 << items_a.size()); ++i) { int total = calc_total(items_a, i); total_a.push_back(total); } vector total_b; for (auto i = 0; i < (1 << items_b.size()); ++i) { int total = calc_total(items_b, i); total_b.push_back(total); } int max_total = 0; sort(total_b.begin(), total_b.end()); for (auto a: total_a) { auto itr = upper_bound(total_b.begin(), total_b.end(), K-a); int ans = a + *(--itr); if (ans <= K) max_total = max(max_total, ans); } cout << max_total << endl; } int calc_total(vector &items, int i) { int total = 0; for (auto j = 0; j < items.size(); j++) { if (i & (1<