思路:每次选打水时间少的,使得总等待时间最少
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
priority_queue<LL,vector<LL>,greater<LL>> heap;
int n;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
LL a;
scanf("%lld",&a);
heap.push(a);
}
LL res=0;
while(heap.size())
{
LL a=heap.top();
heap.pop();
res+=a*(n-1);
n--;
}
printf("%lld",res);
return 0;
}