#include<iostream>
#include<stdio.h>
using namespace std;
int heap_size,n;
int heap[300001];
void swap(int &a,int &b){
int t=a;a=b;b=t;
}
void put(int d){
int son,pa;
heap[heap_size++]=d;
son = heap_size;
while(son>1){
pa=son>>1;
if(heap[son]>=heap[pa])break;
swap(heap[son],heap[pa]);
son = pa;
}
}
int get(){
int pa,son,res;
res = heap[1];
heap[1]=heap[heap_size--];
pa=1;
while(pa*2<=heap_size){
son = pa * 2;
if(son<heap_size&&heap[son+1]<heap[son])son++;
if(heap[pa]<=heap[son])break;
swap(heap[pa],heap[son]);
pa = son;
}
return res;
}
void work(){
int x,y,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
cin >> x;
put(x);
}
for(int i=1;i<n;i++){
x=get();
y=get();
ans+=x+y;
put(x+y);
}
cout << ans <<endl;
}
int main(){
ios::sync_with_stdio(false);
work();
return 0;
}
数据答案是九,可正确答案是15,错错在哪里了?