30 lines
839 B
C++
30 lines
839 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int MAX_N = 10010; // 最大人数
|
|
const int MAX_M = 110; // 最大水龙头数
|
|
int n, m; // n: 同学人数, m: 水龙头数量
|
|
int w[MAX_N]; // 每位同学的接水量
|
|
int taps[MAX_M]; // 每个水龙头的当前结束时间
|
|
int main() {
|
|
cin >> n >> m;
|
|
|
|
// 模拟接水过程
|
|
for (int i = 0; i < n; i++) {
|
|
cin >> w[i];
|
|
|
|
// 找到最先结束的水龙头
|
|
int min_tap = 0;
|
|
for (int j = 1; j < m; j++)
|
|
if (taps[j] < taps[min_tap])
|
|
min_tap = j;
|
|
// 将i号同学的接水量分配给最先结束的水龙头
|
|
taps[min_tap] += w[i];
|
|
}
|
|
// 找到所有水龙头中最大的结束时间
|
|
int result = 0;
|
|
for (int i = 0; i < m; i++)
|
|
result = max(result, taps[i]);
|
|
|
|
cout << result << endl;
|
|
return 0;
|
|
} |