提交时间:2023-08-23 13:39:10

运行 ID: 99620

#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++){ sum[i] = sum[i-1] + a[i]; if(i!=1) ans+=sum[i]; } cout<<ans<<endl; return 0; }