This is the one-dimensional k-means problem, (only slightly) disguised by splitting the data into two parallel lines. The solution method is dynamic programming, which is possible because data can always be grouped into contiguous sets of points. (The k-means problem in higher dimensions is known to be NP-hard.) Reference: "Optimal k-means Clustering in One Dimension by Dynamic Programming" (https://journal.r-project.org/archive/2011-2/RJournal_2011-2_Wang+Song.pdf) The above paper is referenced in: "Fast Exact k-Means, k-Medians and Bregman Divergence Clustering in 1D" (https://arxiv.org/pdf/1701.07204.pdf) I used the algorithm from the first paper, which has runtime O(kn^2); I chose input limits accordingly. The second paper (which I came across only very recently) claims an O(kn)-time algorithm, which I wish I had seen first! My only hesitation about submitting this is that some variation of it has most likely been used before in a contest. However, the paper describing the DP approach is in a journal devoted to R programming, so not one of the mainline CS journals. Moreover, a quick search of Geeks4Geeks did not turn up a tutorial on this (although there is some discussion of it in online forums such as stackexchange). But I have an idea for another variation that I suspect makes it a better choice. Unfortunately I have not had time to code it. ALTERNATE VERSION OF THE PROBLEM: Assume the customers are all arranged along a CIRCULAR street. I believe it to still be the case that the minimum sum of square differences can be achieved by grouping them into sets of contiguous neighbors. (I don't have a proof of this, but it seems intuitively obvious to me. My intuition has been known to be wrong.) Now the "green space" is the interior of the circle and access points can go anywhere inside. I don't know how time consuming it would be to do the pre-computation of the sums of squares, but I think the rest of the algorithm would just be a modification of the above, with extra rows due to the need for checking sets that "wrap around" the input data.