排队打水:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
typedef long long LL;
int n;
int t[N];//总时间
int main()
{
scanf("%d",&n);
for (int i = 0; i < n; i ++ )scanf("%d",&t[i]);
sort(t, t+n);//从小到大排序
LL res = 0;//答案
for (int i = 0; i < n; i ++ )
{
res += t[i]*(n-1-i);//计算公式
}
printf("%lld\n",res);
return 0;
}