P2168 40 tps,除AC全WA
#include <bits/stdc++.h>
using namespace std;
struct tree
{
long long num;
long 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 long n,k,ans1 = 0,ans2 = 0;
priority_queue <tree> q;
int main()
{
cin >> n >> k;
for (long long i = 0;i < n;i++)
{
int x;
cin >> x;
q.push(pos(x,1));
}
if ((n-1) % (k-1))
{
for (long long i = 0;i < k - 1 - (n-1) % (k-1);i++)
{
q.push(pos(0,1));
}
}
long long he = 0,maxn = -2147483647;
while (q.size() != 1)
{
he = 0,maxn = -2147483647;
for (long long i = 0;i < k;i++)
{
he += q.top().num;
maxn = max(q.top().h,maxn);
q.pop();
}
q.push(pos(he,maxn + 1));
ans1 += he;
ans2 = max(maxn,ans2);
}
cout << ans1 << endl << ans2;
return 0;
}