#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; while(L < V){ pair tmp; for(auto i: t){ if(L + i.first <= V){ tmp = i; } } LL pacs = (V - L) / tmp.first; L += tmp.first * pacs; cost += tmp.second * pacs; //cout << tmp.first << " " << tmp.second << endl; } cout << cost << endl; return 0; }