#include #include using namespace std; using ll=long long; using vi=vector; using vll=vector; struct area_t { int s, n, l; }; void calc_area(vll& s, area_t& a, int v, int& base_v, double& min_ave, int& min_n) { vi w; min_n=1; min_ave=s[a.s+min_n]-s[a.s]; for(int n=2;n<=a.n && n<=v;n++) { double ave=(double)(s[a.s+n]-s[a.s])/n; if(min_ave>ave) { min_ave=ave; min_n=n; } } base_v=v/min_n; if(base_v>a.l) base_v=a.l; } ll solve(vll& s, int v) { ll ret=0; int min_base_v, base_v, min_n, n, min_i, i, rest_v; double min_ave, ave; area_t ca; vector cand; rest_v=v; cand.push_back((area_t){0, s.size()-1, v}); for(;;) { for(i=0;iave) { min_ave=ave; min_n=n; min_base_v=base_v; min_i=i; } } ca=cand[min_i]; ret+=(s[ca.s+min_n]-s[ca.s])*min_base_v; rest_v-=min_base_v*min_n; if(rest_v<=0) break; if(ca.l-min_base_v>0) { cand.push_back((area_t){ca.s, min_n, ca.l-min_base_v}); } if(ca.n-min_n>0 && min_base_v>0) { cand.push_back((area_t){ca.s+min_n, ca.n-min_n, min_base_v}); } } return ret; } int main(void) { int n, v, i; vi c, w; vll s; while(scanf("%d%d", &n, &v)==2) { s.resize(n+1); w.resize(n); c.resize(n); s[0]=0; for(i=0;i