#include using namespace std; // const int LIMIT = 1 << 3; // const int DIGIT = 3; const int LIMIT = 1048576; const int DIGIT = 20; int main() { // 1. 入力情報取得. int N, K; cin >> N >> K; int A[DIGIT] = {}; for(int i = 0; i < N; i++) cin >> A[i]; // 2. 商品の重さの合計を計算. // N の 上限が, 2 の 20乗 = 1048576 なので, 全部確認できそう. int ans = 0; for(int i = 0; i < LIMIT; i++){ // 2-1. i を 2進数表記. stringstream ss; ss << static_cast>(i); string bit = ss.str(); // cout << bit << endl; // 2-2. 各商品について, 以下のルールで読み替える. // bit の 各桁が 1 なら, 購入する // bit の 各桁が 0 なら, 購入しない int total = 0; for(int d = 0; d < DIGIT; d++) total += (bit[d] - '0') * A[d]; // 2-3. 商品の重さの合計について, 最大値を更新. if(total <= K) ans = max(ans, total); } // 3. 出力 ~ 終了. cout << ans << endl; return 0; }