You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
611 B
C++
29 lines
611 B
C++
#include <cstdio>
|
|
#include <queue>
|
|
using namespace std;
|
|
typedef long long i64;
|
|
int main()
|
|
{
|
|
priority_queue<i64> p;
|
|
int n;
|
|
while (~scanf("%d", &n))
|
|
{
|
|
while (!p.empty()) p.pop();
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
i64 x;
|
|
scanf("%lld", &x);
|
|
p.push(-x);
|
|
}
|
|
i64 ans = 0, a, b;
|
|
while (p.size() > 1)
|
|
{
|
|
a = p.top(), p.pop();
|
|
b = p.top(), p.pop();
|
|
p.push(a + b);
|
|
ans += -(a + b);
|
|
}
|
|
printf("%lld\n", ans);
|
|
}
|
|
return 0;
|
|
} |