#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n >> m >> k; vector a(n); rep(i,n) cin >> a[i]; vector> tot(4); tot[0].push_back(0); ll ans = 0; rep(i,n){ ll tot1 = a[i]; tot[1].push_back(tot1); rep(j,n){ ll tot2 = tot1 + a[j]; tot[2].push_back(tot2); rep(k,n){ ll tot3 = tot2 + a[k]; tot[3].push_back(tot3); } } } rep(i,4) sort(all(tot[i])); rep(i,k+1){ int q = min(3,i), p = i-q; for(int x:tot[p]){ if(x>m) break; int y = upper_bound(all(tot[q]), m-x) - tot[q].begin() - 1; if(y>=0) chmax(ans, x+tot[q][y]); } } cout << ans << '\n'; return 0; }