The solution to http://dsalgo.openjudge.cn/dsmoochw6/1/

Heap implementation.