提交时间:2023-08-23 13:42:52
运行 ID: 99623
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <iomanip> #include <cmath> #include <queue> #include <map> #include <stack> #include <vector> using namespace std; #define long long LL const int N = 1e4+5; const int INF = 0x3f3f3f3f; int n,a[N],sum[N]; int ans; int main(){ cin >> n; for (int i = 1;i<=n;i++){ cin >> a[i]; } sort(a+1,a+n+1); for (int i = 1;i<=n;i++){ a[i+1]+=a[i]; if(i!=1) ans+=a[i]; sort(a+i+1,a+n+1); } cout<<ans<<endl; return 0; }