29 lines
568 B
C++
29 lines
568 B
C++
|
|
#include <bits/stdc++.h>
|
||
|
|
|
||
|
|
using namespace std;
|
||
|
|
const int N = 10010, M = 200;
|
||
|
|
int n, m;
|
||
|
|
int w[N];
|
||
|
|
int q[M];
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
cin >> n >> m;
|
||
|
|
for (int i = 0; i < n; i++)
|
||
|
|
cin >> w[i];
|
||
|
|
|
||
|
|
for (int i = 0; i < n; i++) {
|
||
|
|
// 找出最小值
|
||
|
|
int t = 0;
|
||
|
|
for (int j = 0; j < m; j++) {
|
||
|
|
if (q[j] < q[t])
|
||
|
|
t = j;
|
||
|
|
}
|
||
|
|
// 将i号同学安排到第t个位置上
|
||
|
|
q[t] += w[i];
|
||
|
|
}
|
||
|
|
int res = 0;
|
||
|
|
for (int i = 0; i < m; i++)
|
||
|
|
res = max(res, q[i]); // 找出最大值就是答案
|
||
|
|
cout << res << endl;
|
||
|
|
return 0;
|
||
|
|
}
|