#include #include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i, a, b) for(int i=(a);i<=(b);i++) #define RFOR(i, a, b) for(int i=(a);i>=(b);i--) #define MOD 1000000007 #define INF 1000000000 #define PI 3.14159265358979 using namespace std; typedef pair P; int main(void) { int n, k; int max = 0; int a[21]; int total = 0; cin >> n >> k; FOR(i, 1, n) { cin >> a[i]; } FOR(i, 1, pow(2, 21) - 1) { total = 0; bitset<20> bit(i); FOR(t, 0, 19) { if (bit[i] == true) { total += a[i + 1]; } } if (total > max&&total <= k) { max = total; } } cout << max << endl; return 0; }