/*{{{ author: ryota2357 */ #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ryota2357 { template inline std::istream& operator>>(std::istream& is, std::pair& P) noexcept { return is >> P.first >> P.second; } template inline std::istream& operator>>(std::istream& is, std::vector& V) noexcept { for (auto& v : V) is >> v; return is; } template inline std::ostream& operator<<(std::ostream& os, const std::vector& V) noexcept { const auto n = V.size() - 1; for (int i = 0; i < n; ++i) os << V[i] << ' '; return os << V.back(); } inline void IN(void) noexcept { return; } template inline void IN(T& t, U&... u) noexcept { std::cin >> t; IN(u...); } template inline void OUT(const T& x) noexcept { std::cout << x << '\n'; } template inline bool chmax(T& a, const T& b) noexcept { return a < b ? a = b, true : false; } template inline bool chmin(T& a, const T& b) noexcept { return a > b ? a = b, true : false; } template inline T read(void) { T ret = 0; char c = getchar(); while ((c < '0' || '9' < c) && c != '-') c = getchar(); const bool f = (c == '-') && (c = getchar()); while ('0' <= c && c <= '9') { ret = 10 * ret + c - '0'; c = getchar(); } return f ? -ret : ret; } template inline T ceil_div(const T& a, const T& b) { assert(b != 0); return (a + (b - 1)) / b; } template inline T max(const std::vector& v) { return *max_element(v.begin(), v.end()); } template inline T min(const std::vector& v) { return *min_element(v.begin(), v.end()); } } // namespace ryota2357 using ll = long long; using pint = std::pair; #define rep(i, a, b) for (ll i = (a); i < ll(b); ++i) #define repr(i, a, b) for (ll i = (a); i >= ll(b); --i) #define each(x, v) for (auto& x : v) #define All(x) (x).begin(), (x).end() #define AllR(x) (x).rbegin(), (x).rend() #define Sort(x) (sort((x).begin(), (x).end())) #define SortR(x) (sort((x).rbegin(), (x).rend())) #define Unique(x) (x.erase(unique((x).begin(), (x).end()), (x).end())) #define Fill(v, n) (fill((v), (v) + sizeof(v) / sizeof(*(v)), (v))) #define INF (1073741823) #define INFL (2305843009213693951ll) using namespace std; using namespace ryota2357; /*}}}*/ namespace debug { void _DEBUG_PRINT_() { static bool done = false; if (done) return; done = true; std::cout << "\033[33m[Debug Mode]\033[m" << std::endl; } void Write(void) { _DEBUG_PRINT_(); std::cerr << std::endl; } template void Write(const std::pair& p) { _DEBUG_PRINT_(); std::cerr << ' ' << '{' << p.first << ',' << p.second << '}' << std::endl; } template void Write(const std::set& V) { _DEBUG_PRINT_(); std::cerr << " {"; for (const auto& v : V) std::cerr << ' ' << v; std::cerr << " }" << std::endl; } template void Write(const std::vector& V, int n = -1) { _DEBUG_PRINT_(); if (n < 0) n = V.size(); std::cerr << " ["; for (int i = 0; i < n; ++i) std::cerr << ' ' << V[i]; std::cerr << " ]" << std::endl; } template void Write(const std::vector>& V, int n = -1) { _DEBUG_PRINT_(); if (n < 0) n = V.size(); std::cerr << " ["; for (int i = 0; i < n; ++i) std::cerr << " {" << V[i].first << ',' << V[i].second << '}'; std::cerr << " ]" << std::endl; } template void Write(const T& t, const U&... u) { _DEBUG_PRINT_(); std::cerr << ' ' << t; Write(u...); } } // namespace debug using namespace debug; int n, m, k; vector a(n); set calc(int kk) { // Write("kk: ", kk); set ret; ret.insert(0); rep(_, 0, kk) { vector nw; each(prev, ret) { rep(i, 0, n) { nw.push_back(a[i] + prev); } } each(nwi, nw) { if (nwi > m) { continue; } ret.insert(nwi); } } return ret; } int main() { IN(n, m, k); a.resize(n); IN(a); auto set1 = calc(k / 2); auto set2 = calc(ceil_div(k, 2)); // Write("set1: ", set1); // Write("set2: ", set2); ll ans = 0; each(e1, set1) { auto it = set2.upper_bound(m - e1); if (it == set2.begin()) { continue; } --it; chmax(ans, e1 + *it); } OUT(ans); return 0; }