提交时间:2023-08-23 12:31:20

运行 ID: 99603

#include <bits/stdc++.h> #define int long long using namespace std; priority_queue<int> q; int n,x,ans=0,tmp; int a[114514]; signed main() { cin >> n; for(int i = 1; i <= n; i++) { cin >> x; //q.push(x); a[i] = x; } /* for(int i = n; i >= 1; i--) { a[i] = q.top(); q.pop(); } */ sort(a+1,a+n+1); for(int i = 2; i <= n; i++) { ans += a[i]+a[i-1]; a[i]=a[i]+a[i-1]; sort(a+i+1,a+n+1); } cout << ans << endl; return 0; }