add minimum distance of array elements