#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template inline string toString(T x) {ostringstream sout;sout< VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; typedef unsigned long long ULL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(auto i: c) #define SORT(c) sort((c).begin(),(c).end()) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() const double EPS = 1e-10; const double PI = acos(-1.0); #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; bool cmp(pair left, pair right){ return (left.second * right.first) > (left.first * right.second); } int main() { cin.tie(0); ios::sync_with_stdio(false); LL N, V; cin >> N >> V; LL C[N + 1]; vector > t(N + 1); t[0] = make_pair(0, 0); FOR(i, 1, N + 1){ cin >> C[i]; t[i] = make_pair(t[i - 1].first + 1, t[i - 1].second + C[i]); } LL L = N, cost = t[N].second; stable_sort(ALL(t), cmp); /* REP(i, N + 1) cout << t[i].first << " " << t[i].second << endl; cout << endl; */ if(L < V){ pair tmp; for(auto i: t){ if(L + i.first < V - N) tmp = i; } LL pacs = (V - N - L) / tmp.first; L += tmp.first * pacs; cost += tmp.second * pacs; //cout << tmp.first << " " << tmp.second << endl; const LL MAX = 10e10; vector> dp(N + 1, vector(V - L + 1, MAX)); REP(i, N + 1) dp[i][0] = 0; for(auto i = N; i != 0; i--) REP(j, V - L + 1){ for(auto k: t){ if(k.first <= i){ int litter = min(j + k.first, V - L); dp[k.first][litter] = min(dp[k.first][litter], dp[i][j] + k.second); } } } LL m = MAX; REP(i, N + 1) m = min(m, dp[i][V - L]); cost += m; /* REP(i, N + 1){ REP(j, V - L + 1) cout << dp[i][j] << " "; cout << endl; } */ } cout << cost << endl; return 0; }