#include #include using namespace std; using ll=long long; using vi=vector; using vll=vector; void solve_r(vi& v, vi& c, int m, int idx, ll ac, ll& result) { vi w; if(idx>=v.size()) { if(m==0 && result>ac) { result=ac; } return; } w=v; for(int i=0;i<=m;i++) { w[idx]=v[idx]+i; if(w[idx]>w[idx-1]) break; solve_r(w, c, m-i, idx+1, ac+(ll)c[idx]*i, result); } } ll solve(vi& v, vi& c, int m) { vi w; ll ret; ret=(ll)c[0]*m; w=v; for(int i=0;i<=m;i++) { w[0]=v[0]+i; solve_r(w, c, m-i, 1, (ll)c[0]*i, ret); } return ret; } int main(void) { int n, v, i, m; vi c, w; vll s; double ave, min_ave; int min_idx, base_v; ll result; while(scanf("%d%d", &n, &v)==2) { s.resize(n); w.resize(n); c.resize(n); for(i=0;i0)?s[i-1]:0)+c[i]; } if(v<=n) { printf("%lld\n", s[n-1]); continue; } v-=n; min_ave=c[0]; min_idx=0; for(i=1;iave) { min_ave=ave; min_idx=i; } } base_v=v/(min_idx+1); m=v-base_v*(min_idx+1); for(i=0;i<=min_idx;i++) { w[i]+=base_v; } result=s[n-1]+s[min_idx]*base_v+solve(w, c, m); printf("%lld\n", result); } return 0; }