#include<iostream>
#include<queue>
using namespace std;
template<class T>
int getLength(T& arr);
int main(){
priority_queue<int,vector<int>,greater<int> > small_heap;
int arr[] = {3,4,1,2};
int length = getLength(arr);
int sum = 0;
int i=0;
int help =0;
while(i<length){
small_heap.push(arr[i]);
i++;
}
while(small_heap.size() != 1){
//出堆两次
help += small_heap.top();
small_heap.pop();
help += small_heap.top();
small_heap.pop();
//计量损失,并放入新值
sum += help;
small_heap.push(help);
help = 0;
}
cout << sum;
return 0;
}
template<class T>
int getLength(T& arr){
return sizeof(arr)/sizeof(arr[0]);
}