#include #include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) typedef long long ll; using namespace std; int main() { int n; ll v; cin >> n >> v; vector c(n); repeat (i,n) cin >> c[i]; if (v <= n) { cout << accumulate(c.begin(), c.end(), 0ll) << endl; return 0; } v -= n; // the restriction, that all fruits must be used, is fulfilled now. vector acc(n+1); repeat (i,n) acc[i+1] = acc[i] + c[i]; const int l = 2e7; // ??? vector dp(l+1, LLONG_MAX); dp[0] = 0; repeat (i,l) { repeat (j,min(i+1,n)) { dp[i+1] = min(dp[i+1], dp[i-j] + acc[j+1]); } } vector eff(l); repeat (i,l) eff[i] = i+1; sort(eff.begin(), eff.end(), [&](int a, int b) { return dp[a] * b < dp[b] * a; // sort by the efficiency }); int e = eff.front(); cout << acc[n] + (v / e) * dp[e] + dp[v % e] << endl; return 0; }