用优先队列
贪心做
#include<bits/stdc++.h>
using namespace std;
int n;
int a[10001];
priority_queue<int>q;
int main(){
cin>>n;
int x;
for(int i=1;i<=n;i++){
cin>>x;
q.push(x);
}
long long cnt=0;
for(int i=1;i<n;i++){
int temp=q.top();
cnt+=q.top();
q.pop();
temp+=q.top();
cnt+=q.top();
q.pop();
q.push(temp);
}
long long ans=0;
ans=cnt%1000000007;
cout<<ans<<endl;
return 0;
}