思路:
直接用堆来做
c o d e code code
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int n;
priority_queue<int> q;
int main()
{
scanf("%d", &n);
for(int i=1; i<=n; i++)
{
int x;
scanf("%d", &x);
q.push(-x);
}
int ans=0;
for(int i=1; i<n; i++)
{
int x=-q.top();
ans+=x;
q.pop();
int y=-q.top();
ans+=y;
q.pop();
q.push(-x-y);
// cout<<ans<<' '<<x+y<<endl;
}
printf("%d", ans);
return 0;
}