Help me in solving P3169 problem

My issue

If anyone was able to solve this question…

Problem Link: Make K Most Frequent Practice Coding Problem