#include #include using namespace std; using namespace atcoder; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T& x, const T& y){return (x bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; int main(){ ll n, m, k; cin >> n >> m >> k; VI a(n); REP(i,n) cin >> a[i]; n++; a.push_back(0); int l=k/2, r=(k+1)/2; VI x, y; function f=[&](ll sum, int i){ if(i==l){ x.push_back(sum); return; } REP(j,n) f(sum+a[j],i+1); }; f(0,0); function g=[&](ll sum, int i){ if(i==r){ y.push_back(sum); return; } REP(j,n) g(sum+a[j],i+1); }; g(0,0); sort(ALL(y)); ll ans=0; for(auto z:x){ auto it=upper_bound(ALL(y),m-z); if(it==y.begin()) continue; chmax(ans,z+*prev(it)); } cout << ans << endl; return 0; }