You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
330 B

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long LL;
int a[N];
LL res;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) res += a[i] * (n - i - 1);
printf("%lld", res);
return 0;
}