提交时间:2023-08-23 13:48:43
运行 ID: 99627
#include <bits/stdc++.h> #define int long long using namespace std; int n,x,ans=0; int a[1000005]; signed main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } sort(a+1,a+n+1); for(int i = 2; i <= n; i++){ ans += a[i]+a[i-1]; a[i]+=a[i-1]; sort(a+i,a+n+1); } cout << ans << endl; return 0; }