#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define REPR(i, n) for(ll i = n;i >= 0;i--) #define FOR(i, m, n) for(ll i = m;i < n;i++) #define FORR(i, m, n) for(ll i = m;i >= n;i--) #define REPO(i, n) for(ll i = 1;i <= n;i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(),n.end() #define MOD 1000000007 #define P pair ll ans = 0; vector dp(11000, INF); int main() { ll n, v; cin >> n >> v; vector s(n), r(n); REP(i, n) { cin >> s[i]; ans += s[i]; } v -= n; if (v <= 0) { cout << ans << endl; return 0; } r[0] = s[0]; REP(i, n - 1) r[i + 1] = r[i] + s[i + 1]; vector> p(n); REP(i, n) p[i] = pair((double)r[i] / (i + 1), i); sort(ALL(p)); if (v > 10000) { v -= 10000; ans += r[p[0].second] * (v / (p[0].second + 1)); v %= p[0].second + 1; v += 10000; } dp[0] = 0; REP(i, n) { REP(j, v + 1) { dp[min(v, j + i + 1)] = min(dp[min(v, j + i + 1)], dp[j] + r[i]); } } cout << ans + dp[v] << endl; }