ll@n,@m,l[n+2],z=0; rd(((l+1))(n)); l[0]=-ll_inf; l[n+1]=ll_inf; rep(m){ ll@f,@b,@w; ll i=bsearch_min[ll,i,0,n+2](l[i]>=f); z+=max(b,w+l[i-1]-f,w-l[i]+f); } wt(z);