closest pairs algorithm c++ implementation