#include #define show(x) std::cerr << #x << " = " << x << std::endl using ld = long double; using ll = long long; template constexpr T INF = std::numeric_limits::max() / 4; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int N; ll V; std::cin >> N >> V; std::vector C(N); ll sum = 0; for (auto& e : C) { std::cin >> e, sum += e, V--; } if (V <= 0) { return std::cout << sum << std::endl, 0; } for (int i = 1; i < N; i++) { C[i] += C[i - 1]; } ld cp = 1e10; int mini = -1; for (int i = 0; i < N; i++) { const ld per = (ld)C[i] / (i + 1); if (cp > per) { cp = per, mini = i; } } const int L = N * (mini + 1), use = std::max(0LL, (V - L + 1 + mini) / (mini + 1)); sum += use * C[mini], V -= (mini + 1) * use; std::vector dp(L, INF); // 合計iリットル使う最安値 dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < L; j++) { dp[j] = std::min(dp[j], dp[j - i - 1] + C[i]); } } std::cout << dp[V] + sum << std::endl; return 0; }