C++
$\color{#cc33ff}{— > 算法基础课题解}$
思路:
贪心
$按照从小到大的顺序排队,总时间最小$
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int n;
int t[N];
int main() {
cin >> n;
for (int i = 0; i < n; i ++) cin >> t[i];
sort (t, t + n);
ll res = 0;
for (int i = 0; i < n; i ++) res += t[i] * (n - i - 1);
cout << res;
return 0;
}