Can you share the code for doing in o(k)

i am not able to get the code can you please share the code for this problem

hello @alakhprivate
i dont think it is solvable in O(k).

if u r looking for priority queue approach then its time complexity is
klog(n)