#include using namespace std; using lint = long long; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template istream &operator>>(istream &is, vector &vec) { for (auto &v : vec) is >> v; return is; } template ostream &operator<<(ostream &os, const vector &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; } #ifdef HITONANODE_LOCAL #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl #else #define dbg(x) #endif int main() { int N, V; cin >> N >> V; vector C(N); cin >> C; vector v2c(N + 1); REP(i, N) v2c[i + 1] = v2c[i] + C[i]; vector dp(N * 2 + 3, 1e18); dp[0] = 0; FOR(i, 1, dp.size()) { if (i < int(v2c.size())) { chmin(dp[i], v2c[i]); } REP(j, i) { chmin(dp[i], dp[j] + dp[i - j]); } } dbg(dp); auto solve = [&](auto &&solve, lint v) -> vector { vector ret(N, 1e18); if (v + N < dp.size()) { fill(ret.begin(), ret.end(), 0); REP(i, N) if (v + i >= 0) ret[i] = dp[v + i]; } else { int head = (v - N) / 2; vector half = solve(solve, head); REP(i, half.size()) REP(j, half.size()) { REP(l, dp.size()) { lint k = head * 2 + i + j + l - v; if (k >= 0 and k < int(ret.size())) chmin(ret[k], half[i] + half[j] + dp[l]); } } } return ret; }; cout << v2c[N] + solve(solve, V - N)[0] << '\n'; }