傳送門
思路:
#include<bits/stdc++.h>
using namespace std;
# define ll long long
priority_queue<int,vector<int>,greater<int> >a;
int main()
{
int n;
scanf("%d",&n);
for(int i = 1; i <= n; i++)
{
int b;
scanf("%d",&b);
a.push(b);
}
ll ans = 0;
while(a.size() != 1)
{
int x = a.top();
a.pop();
int y = a.top();
a.pop();
x = x + y;
a.push(x);
ans += x;
}
printf("%lld\n",ans);
}