Find out top K largest element

IN THE ABOVE QUESTION I USED min_heap but
when i dry run the test case for my solution …i found that
my answer for first test case is wrong.

why?—
first line represent test case followed by n and k
and then n elements

link for code-- https://ide.codingblocks.com/s/319682

2

5 2

12 5 787 1 23

7 3

1 23 12 9 30 2 50

Hey @akshay2229
I believe problem is on line 27,it should be :
push_heap(answer.begin(),answer.end(),greater());

I hope your issue is resolved now :slight_smile: