#include #include #include #include #include #include #include using namespace std; vector calc_weights(vector a, int k) { set ws; int n = a.size(); int limit = 1 << n; for (int i = 0; i < limit; i++) { int w = 0; for (int j = 0; j < n; j++) { if ((i >> j) & 1) { w += a[j]; } } if (w <= k) { ws.insert(w); } } return vector(ws.begin(), ws.end()); } int main() { int n, k, a; cin >> n >> k; int n2 = n / 2; vector as1, as2; for (int i = 0; i < n; i++) { cin >> a; (i < n2 ? as1 : as2).emplace_back(a); } int ans = 0; auto w1 = calc_weights(as1, k); auto w2 = calc_weights(as2, k); for (auto x : w1) { for (auto y : w2) { if (x + y <= k) { ans = max(ans, x + y); } } } cout << ans << endl; return 0; }