#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
int n, m;
ll a[maxn];
struct node {
ll val;
node(ll a = 0) {
val = a;
}
friend bool operator < (node a, node b) {
return a.val > b.val;
}
};
priority_queue<node> Q;
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
sort(a + 1, a + n + 1, greater<ll>() );
for(int i = 1; i <= m; i ++) {
Q.push(node(a[i]));
}
for(int i = m + 1; i <= n; i ++) {
ll now = Q.top().val;
Q.pop();
Q.push(now + a[i]);
}
ll ans = 0;
while(!Q.empty()) {
ans = Q.top().val;
Q.pop();
}
printf("%lld\n", ans);
return 0;
}
记不住发一下
最新推荐文章于 2024-08-25 22:03:20 发布