1. Maintain K-fork tree, pay attention to 0
2. Use the heap to maintain the minimum frequency and length, and each time you merge up, statistical answer
3 when merging. if N (k-1) =1 then do not need to fill 0 (because each merge is equivalent to adding K-1 nodes, all if you can merge into one node, Then must meet the above conditions)
# include <queue> # include <cstdio> # include <cstring> # include <iostream> # include <algori
Thm> # define LL Long long using namespace std;
Inline LL Read () {LL x = 0, f = 1;
char ch = getchar ();
while (! isdigit (CH)) {if (ch = = '-') f =-1LL;
ch = getchar ();
} while (IsDigit (CH)) {x = 1LL * x * + ch-' 0 ';
ch = getchar ();
} return x * f;
} struct p{LL len, P; P (ll x = 0, ll y = 0): Len (x), p (y) {} bool operator< (const P & RHS) const {if (p = = RH
S.P) return len > Rhs.len;
return p > rhs.p;
}} an;
Priority_queue <P> Q;
int main () {//Freopen ("Debug.in", "R", stdin);
LL N, K;
n = Read (), k = Read ();
for (int i = 1; I <= n; + + i) {LL x = Read ();
Q.push (P (0, X));
} while (K > 2 && n% (k-1)! = 1) { n + +;
Q.push (P (0, 0));
} while (Q.size () > 1) {int p = k;
ll ll = 0, pp = 0; while (P &&!)
Q.empty ()) {P E = Q.top ();
Q.pop ();
LL = max (ll, E.len + 1), pp + = E.P;
P--;
} an.p + = pp, An.len = max (An.len, LL);
Q.push (P (ll, pp));
} P E = Q.top ();
printf ("%lld\n%lld", AN.P, An.len);
return 0; }