#include using namespace std; using ll = long long; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll n, m, k; cin >> n >> m >> k; vector a1(n + 1); for (ll i = 0; i < n; i++) { cin >> a1[i]; } n++; sort(a1.begin(), a1.end()); vector a2; for (ll i = 0; i < n; i++) { for (ll id = 0; id < n; id++) { a2.push_back(a1[i] + a1[id]); } } sort(a2.begin(), a2.end()); vector a3; for (ll i = 0; i < n; i++) { for (ll id = 0; id < n; id++) { for (ll idx = 0; idx < n; idx++) { a3.push_back(a1[i] + a1[id] + a1[idx]); } } } sort(a3.begin(), a3.end()); if (k == 1) { cout << *prev(upper_bound(a1.begin(), a1.end(), m)) << endl; } else if (k == 2) { cout << *prev(upper_bound(a2.begin(), a2.end(), m)) << endl; } else if (k == 3) { cout << *prev(upper_bound(a3.begin(), a3.end(), m)) << endl; } else if (k == 4) { ll ans = 0; for (ll i = 0; i < a2.size(); i++) { if (a2[i] > m) { continue; } auto key = m - a2[i]; auto it = prev(upper_bound(a2.begin(), a2.end(), key)); chmax(ans, a2[i] + *it); } cout << ans << endl; } else if (k == 5) { ll ans = 0; for (ll i = 0; i < a2.size(); i++) { if (a2[i] > m) { continue; } auto key = m - a2[i]; auto it = prev(upper_bound(a3.begin(), a3.end(), key)); chmax(ans, a2[i] + *it); } cout << ans << endl; } else { ll ans = 0; for (ll i = 0; i < a3.size(); i++) { if (a3[i] > m) { continue; } auto key = m - a3[i]; auto it = prev(upper_bound(a3.begin(), a3.end(), key)); chmax(ans, a3[i] + *it); } cout << ans << endl; } return 0; }