6. 排队打水 排序不等式

贪心思路:让最麻利的人最先打水

 

 注意是求总等待时间最短,是等待时间

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 100010;
 5 int t[N];
 6 int main() {
 7     int n;
 8     cin >> n;
 9     for (int i = 0; i < n; i++) {
10         cin >> t[i];
11     }
12     sort(t, t + n);
13     ll res = 0;
14     for (int i = 0; i < n; i++) {
15         res += t[i] * (n - i - 1);
16     }
17     cout << res << endl; 
18     return 0;
19 }
原文地址:https://www.cnblogs.com/fx1998/p/13460256.html