Top K needs only K live candidates
After counting U unique values, a min-heap of size K keeps the weakest current winner at its root. Each candidate costs O(log K), avoiding an O(U log U) full sort when K is small. Final K results are then sorted for the public output contract.