#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector vec; typedef pair P; #define rep(n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define in(a) cin >> a; #define out(a) cout << a << endl; #define REP(i, x, n) for(int i = x; i < n; i++) #define INF 100000000 int dy[] = { 1,0,-1,0 }, dx[] = { 0,1,0,-1 }; int main() { int n, k, res = 0; cin >> n >> k; int a[25] = { 0 }; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < (1 << n); i++) { int sum = 0; for (int j = 0; j < n; j++) { if ((1 & i >> j) == 1) { sum += a[j]; //cout << a[j] << " "; } } //cout << endl; if (k >= sum) res = max(res, sum); } cout << res << endl; return 0; }