C++ 代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100010;
int n;
int a[N];
int cnt, ans;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i ++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n - 1; i ++){
cnt += a[i];
ans += cnt;
}
cout << ans;
return 0;
}