# Given N points on a number line and m total distances between those points, are there efficent ways to optimize for particular values in m?

Given a set of distances S, choose N unique points P on a number line such that the distances between the N points occur in S as much as possible. That is, maximize the occurence in S of the distances between the N points.

For example:

S = {2, 4}, N = 4

One answer would be P = {2, 4, 6, 8}, since the distances between the points P are 2, 2, 2, 2, 4, 4, 6. Only 6 is not in S.

or

S = {7, 13, 14, 22} N = 4501

I'm not looking for an exact answer (although an exact answer wouldn't hurt) but rather I am trying to avoid reinventing the wheel (fun though it may be). What mathematical tools could I use to avoid bruteforcing the possible values of P. How should how would you approach this problem?

Some comments expanding on gowers' hunch: we may as well assume that the elements of S have gcd 1. If the size of the set is |S| = m and the sum of the elements of S is k then taking a block of N consecutive integers for $N \geq m$ gives (mN - k) pairs. There's also a theoretical maximum of $mN - \binom{m + 1}{2}$: every element of any N-set can be the larger half of at most m pairs, except that the smallest element can be the larger half of at most 0, the second-smallest can be the larger half of at most 1, etc., and the m-th smallest can be the larger half of at most (m - 1).
This feels to me more like additive combinatorics than additive geometry, though the flavour of the problem may change when N gets large. If f is the characteristic function of A, g is the characteristic function of -A, and h is the characteristic function of the set you want the differences to lie in, then you seem to be interested in the value of $\langle f*g,h\rangle$. This makes sense on the Fourier side, so if you are looking for estimates rather than exact answers it could possibly help to look at $\langle |\hat{f}|^2,\hat{h}\rangle$, to which it is equal.