링크 : https://www.acmicpc.net/problem/2798
/*
문제 : 블랙잭
링크 : https://www.acmicpc.net/problem/2798
*/
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> v;
for(int i = 0, tmp; i < N; i++){
cin >> tmp;
v.push_back(tmp);
}
int result = 0;
for(int i = 0; i < N; i++){
for(int j = i + 1; j < N; j++){
for(int k = j + 1; k < N; k++){
if(v[i] + v[j] + v[k] <= M && v[i] + v[j] + v[k] > result)
result = v[i] + v[j] + v[k];
}
}
}
cout << result;
return 0;
}