#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
priority_queue<int> q;
int n,temp,ans,a,b;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&temp);
q.push(-temp);
}
while(q.size()>=2)
{
a=q.top();
q.pop();
b=q.top();
q.pop();
q.push(a+b);
ans-=a+b;
}
printf("%d\n",ans);
return 0;
}
时间: 2024-10-12 17:40:28