An interesting problem, which is described
here[
^], including how to use a heap. I wasn't sure if the question meant "use the C++ heap" (dynamic memory allocation) or "use a heap data structure" (which is what the article suggests to improve the algorithm's efficiency).
This isn't just a few lines of code, so I doubt you'll find anyone here who will supply you with it. Besides, that wouldn't do you any good, because you're supposed to learn from this assignment, and being spoon-fed the solution wouldn't do that at all. The article contains a good description of the algorithm, so get to work. This is not a trivial exercise, so you must already have C++ experience. Once you have some code that tries to implement it, post it here if you've got questions or problems. But again, in the same way that this isn't a code-to-order service, it's not a debugging service for those who simply say, "Why doesn't my code work?"