#include #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; int main() { int N; ll V; cin >> N >> V; vector cost(N); ll suma = 0; for (int i = 0; i < N; i++) { cin >> cost[i]; suma += cost[i]; } if (V <= N) { cout << suma << endl; return 0; } V -= N; vector sum(N); vector> newcost(N); for (int i = 0; i < N; i++) { if (i == 0) { sum[i] = cost[i]; } else { sum[i] = sum[i - 1] + cost[i]; } newcost[i] = make_pair((long double)sum[i] / (i + 1), i); } sort(newcost.begin(), newcost.end()); constexpr ll REST = 50000; const ll res = min(REST, V); const int ind = newcost[0].second; const ll vol = (V - res) / (ind + 1); V -= vol * (ind + 1); suma += vol * sum[ind]; vector> dp(N, vector(V + 1, INF)); //i番目まででLリットル作るときの最小コスト for (ll i = 0; i <= V; i++) { dp[0][i] = sum[0] * i; } for (ll i = 1; i < N; i++) { for (ll l = 0; l <= V; l++) { dp[i][l] = dp[i - 1][l]; } for (ll l = 0; l <= V; l++) { if (l >= (i + 1)) { dp[i][l] = min(dp[i][l], dp[i][l - (i + 1)] + sum[i]); } } } cout << suma + dp[N - 1][V] << endl; return 0; }