@yanbinmu,你的down写的有点问题,改成while循环就好了。
```cpp
#include <bits/stdc++.h>
using namespace std;
int s[15005],tail=0;
void up(int x){
if(s[x/2]>s[x]){
swap(s[x/2],s[x]);
up(x/2);
}
return;
}
void insert(int x){
s[++tail]=x;
if(tail>1)up(tail);
return;
}
void down(int x){
while(x*2<=tail){
int t=2*x;
if(s[t]<s[t+1] || t+1>tail)
t=t;
else
t++;
if(s[t]<s[x]){
swap(s[t],s[x]);
x=t;
}
else
break;
}
return;
}
void del(){
s[1]=s[tail--];
down(1);
}
int get(){
int t=s[1];
del();
return t;
}
int main(){
int n;
cin>>n;
for(int i = 1;i<=n;i++){
int t;
cin>>t;
insert(t);
}
long long ans=0;
while(tail>=2){
int t1=get();
int t2=get();
ans+=(t1+t2);
insert(t1+t2);
}
cout<<ans;
return 0;
}
```
by Andy_Li @ 2022-08-21 09:20:10
递归的 _return_ **只能返回上一层**,而 _while_ 循环的 _break_ 是** _退出整个循环_ **,所以因该应该用 _while_
by Andy_Li @ 2022-08-21 09:23:30