提交时间:2024-08-19 18:04:35

运行 ID: 167810

#include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <map> #define range(i,a,b) for(int i=a;i<=b;++i) #define LL long long #define rerange(i,a,b) for(int i=a;i>=b;--i) #define fill(arr,tmp) memset(arr,tmp,sizeof(arr)) using namespace std; int n; vector<int>num(10005); void init(){ cin>>n; range(i,1,n)cin>>num[i]; sort(num.begin()+1,num.begin()+1+n); } void solve(){ LL ans=0; range(i,2,n){ ans+=num[i-1]+num[i]; num[i]+=num[i-1]; sort(num.begin()+i,num.begin()+1+n); } cout<<ans<<endl; } int main() { init(); solve(); return 0; }