Suppose we have to allocate x amount to k desired amounts. Is there algorithm to do this that minimizes the squared distance between the actual k allocated values and the k desired amounts?
For example suppose we need to allocate x=5 to k=3 desired amounts of 2,-3,4.
We could allocate the 5 to 2,-3,6 producing squared distance of 0^2 + 0^2 + 2^2 = 4.
We are allowed to allocate negative amounts or any amount to the k amounts. The only restriction is the allocated amounts must sum to original x. Also allocated amounts do not need to be integers, only real numbers.