#include #include // #include using namespace std; // using namespace atcoder; // using mint = modint998244353; #define i64 int_fast64_t const i64 INF = INT64_MAX; const i64 ERR = INT64_MIN; const i64 MOD = 998244353; // 切り上げ i64 ceil_devide(i64 x, i64 y) { return (x + y - 1) / y; } // 切り捨て i64 floor_devide(i64 x, i64 y) { return x / y; } i64 sum_linear(i64 n) { return n * (n+1) / 2; } int main() { i64 n,m,k; cin >> n >> m >> k; vector a(n+1); for (size_t i = 0; i < n; i++) { cin >> a.at(i); } a.at(n) = 0; set merged; if (k >= 2) { for (size_t i1 = 0; i1 < n+1; i1++) { if (k >= 4) { for (size_t i2 = 0; i2 < n+1; i2++) { if (k >= 6) { for (size_t i3 = 0; i3 < n+1; i3++) { merged.insert(a.at(i1) + a.at(i2) + a.at(i3)); } } else { merged.insert(a.at(i1) + a.at(i2)); } } } else { merged.insert(a.at(i1)); } } } else { merged.insert(0); } auto pos1 = merged.begin(); auto pos2 = merged.end(); pos2--; i64 best = 0; if (k % 2 == 0) { while (pos1 != pos2) { if (*pos1 + *pos2 > m) { pos2--; } else { best = max(best, *pos1 + *pos2); pos1++; } } } else { for (size_t i = 0; i < n+1; i++) { while (pos1 != pos2) { if (*pos1 + *pos2 + a.at(i) > m) { pos2--; } else { best = max(best, *pos1 + *pos2 + a.at(i)); pos1++; } } } } cout << best << endl; return 0; }