去发题解好吗?
by wh_ZH @ 2017-06-29 19:49:25
咳咳。。可以
by LKY2002 @ 2017-06-30 15:18:21
```cpp
#include<stdio.h>
int heap[30001],m,n,i,c,ans=0,size;
int change(int &a,int &b){
int t;
t=a;a=b;b=t;
}
void put(int m){
int now,next;
size++;
heap[size]=m;now=size;
while(now>1){
next=now/2;
if(heap[now]>=heap[next])return;
change(heap[next],heap[now]);
now=next;
}
}
int get(){
int res=heap[1],now,next;
heap[1]=heap[size];size--;
now=1;
while(now*2<=size){
next=now*2;
if(next<size&&heap[next]>heap[next+1])next++;
if(heap[next]>=heap[now])return res;
else change(heap[next],heap[now]);
now=next;
}
return res;
}
int main(){
int j,k;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&k);
put(k);
}
int x,y;
for(k=1;k<n;k++){
x=get();
y=get();
ans+=x+y;
put(x+y);
}
printf("%d",ans);
}
```
by 腾昊一世 @ 2017-07-02 15:24:09
@[周何](/space/show?uid=18378) 题解的词条被锁定,你**提交试试
by ylsoi @ 2017-07-05 15:57:52