#include<cstdio> #include<queue> using namespace std; int main() { priority_queue<int> pque; int n; scanf("%d", &n); for (int i = 0 ; i < n ; ++ i) { int leaf; scanf("%d", &leaf); pque.push(-leaf); } int sum = 0 ; //WRL中间结果 while (pque.size() > 1) { int lhs = pque.top(); pque.pop(); int rhs = pque.top(); pque.pop(); int res = lhs + rhs; sum = sum + res; pque.push(res); } printf("%d\n", -sum); }