closest pair algo from Stanford Algorithms lecture