#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() { int n, m, k; cin >> n >> m >> k; vector a(n + 1); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); n++; vector a2; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a2.push_back(a[i] + a[j]); } } sort(a2.begin(), a2.end()); vector a3; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int jj = 0; jj < n; jj++) { a3.push_back(a[i] + a[j] + a[jj]); } } } sort(a3.begin(), a3.end()); n++; if (k == 1) { cout << *prev(upper_bound(a.begin(), a.end(), m)) << endl; } if (k == 2) { cout << *prev(upper_bound(a2.begin(), a2.end(), m)) << endl; } if (k == 3) { int ans = 0; for (int i = 0; i < a.size(); i++) { if (a[i] > m) { continue; } auto key = m - a[i]; auto it = prev(upper_bound(a2.begin(), a2.end(), key)); chmax(ans, a[i] + *it); } cout << ans << endl; } if (k == 4) { int ans = 0; for (int 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; } if (k == 5) { int ans = 0; for (int 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; } if (k == 6) { int ans = 0; for (int 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; }