基本思路:
和之前一题类似,只不过算的是总体等待时间;
关键点:
无;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> #include<map> #include<queue> #include<set> #include<stack> using namespace std; int m, n; vector<int>peo; vector<vector<int>>t; void charge() { for (int i = 0; i < peo.size(); i++) { t[i%m].push_back(peo[i]); } int cnt = 0; for (int i = 0; i < m; i++) { int c = 0; for (int j = 0; j < t[i].size(); j++) { c += t[i][j]; cnt += c; } } cout << cnt; } int main() { cin >> n >> m; peo.resize(n); t.resize(m); //fill(fin.begin(), fin.end(), 0); for (int i = 0; i < n; i++) { cin >> peo[i]; } sort(peo.begin(), peo.end()); charge(); return 0; }