Use C++ STL priority_queue can solve it