32 lines
576 B
C++
32 lines
576 B
C++
#include <algorithm>
|
|
#include <iostream>
|
|
#include <queue>
|
|
using namespace std;
|
|
|
|
const int MaxN = 1e4 + 5;
|
|
int N, M, W[MaxN], nowTime, ans;
|
|
priority_queue<int> prq, q;
|
|
|
|
int main() {
|
|
cin >> N >> M;
|
|
for (int i = 1; i <= N; i++) {
|
|
cin >> W[i];
|
|
ans = max(W[i],ans);
|
|
}
|
|
if (N<=M) {
|
|
cout<<ans<<endl;
|
|
return 0;
|
|
}
|
|
for (int i = 1; i <= M; i++) {
|
|
q.push(-W[i]);
|
|
}
|
|
for (int i = M + 1; i <= N; i++) {
|
|
int num = q.top();q.pop();
|
|
q.push(num-W[i]);
|
|
}
|
|
while (q.size() > 0) {
|
|
ans = max(ans, -q.top());
|
|
q.pop();
|
|
}
|
|
cout << ans << endl;
|
|
} |