你就用吧

#include<bits/stdc++.h>
using namespace std;
const int maxx=1e9;
int n,m;
int minv[30],mins[30];
int h[30],r[30],ans=maxx;
int v,s;//VS code(bushi)
void dfs(int dep){
    if(!dep){
        if(v==n)ans=min(ans,s);
        return;

    }
    for(r[dep]=min((int)sqrt(n-v),r[dep+1]-1);r[dep]>=dep;r[dep]--){
        for(h[dep]=min((int)((double)(n-v)/r[dep]*r[dep]),h[dep+1]-1);h[dep]>=dep;h[dep]--){
            if(v+minv[dep]>n)continue;
            if(s+mins[dep]>ans)continue;
            if(2*(n-v)/r[dep]+s>ans)continue;
            if(dep==m)s+=r[dep]*r[dep];
            s+=2*r[dep]*h[dep];
            v+=r[dep]*r[dep]*h[dep];
            dfs(dep-1);
            if(dep==m)s-=r[dep]*r[dep];
            s-=2*r[dep]*h[dep];
            v-=r[dep]*r[dep]*h[dep];
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        minv[i]=minv[i-1]+i*i*i;
        mins[i]=mins[i-1]+2*i*i;
    }
    h[m+1]=r[m+1]=maxx;
    dfs(m);
    if(ans==maxx)puts("0");
    else printf("%d\n",ans);
    return 0;
}

admin别给我删了