#include小顶堆实现哈夫曼树#include using namespace std;#define read(x) scanf("%lld",&x)int main(){ priority_queue ,greater >q; long long n,temp,sum; read(n); if(n==1) { read(temp); printf("%lld\n",temp); return 0; } while(n--) { read(temp); q.push(temp); } sum=0; while(q.size()>1) { temp=q.top(); q.pop(); temp+=q.top(); q.pop(); sum+=temp; q.push(temp); } printf("%lld\n",sum);}