Files
OI-source/1.1090.cpp
2023-08-03 09:22:52 +08:00

24 lines
408 B
C++

// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int n,x,res;
priority_queue<int,vector<int>,greater<int>> Q;
int main()
{
scanf("%d",&n);
while(n-->0)
{
scanf("%d",&x);
Q.push(x);
}
while(Q.size()>=2)
{
int a=Q.top(); Q.pop();
a+=Q.top(); Q.pop();
Q.push(a);
res+=a;
}
printf("%d\n",res);
return 0;
}