POJ 3253: Fence Repair, Heap method