#include #include using namespace std; int N; int64_t V; vector C; vector W; // iリトッルを増やすのに必要なコスト int main() { cin >> N >> V; C.resize(N); for(auto &c: C) cin >> c; W = vector(N + 1); for(int i = 0; i < N; i++) { W[i + 1] = W[i] + C[i]; } V -= N; int64_t cost = W[N]; // 全て1L購入する // 貪欲法 // W[i] / iが最大なものを選択する. int max_i = 1; for(int i = 1; i <= N; i++) { // W[max_i] / max_i < W[i] / i if(W[max_i] * i < W[i] * max_i) { max_i = i; } } while(V > 10100) { int64_t t = max(1, (V - 20000) / max_i); V -= t * max_i; cost += t * W[max_i]; } if(V > 0) { // 動的計画法 vector dp(V + 1, 1LL << 60); dp[0] = 0; for(int i = 0; i <= V; i++) { for(int j = 1; j <= N && i + j <= V; j++) { dp[i + j] = min(dp[i + j], dp[i] + W[j]); } } cost += dp[V]; } cout << cost << endl; }