P2168,0pts,全WA
#include <bits/stdc++.h>
using namespace std;
struct tree
{
long num;
long h;
bool operator< (const tree &x)
const
{
if(num != x.num) return num > x.num;
return h > x.h;
}
};
tree pos(int num1,int h1)
{
tree w;
w.num = num1;
w.h = h1;
return w;
}
long n,k,ans1 = 0,ans2 = 0;
priority_queue <tree> q;
int main()
{
cin >> n >> k;
if ((n-1) % (k-1))
{
for (int i = 0;i < (n-1) % (k-1) + 1;i++)
{
q.push(pos(0,0));
}
}
for (int i = 0;i < n;i++)
{
int x;
cin >> x;
q.push(pos(x,1));
}
while (q.size() == 1)
{
long he = 0,maxn = -1e6;
for (int i = 0;i < k;i++)
{
he += q.top().num;
maxn = max(q.top().h,maxn);
q.pop();
}
q.push(pos(he,maxn));
ans1 += he;
ans2 = max(maxn,ans2);
}
cout << ans1 << endl << ans2;
return 0;
}