Minimum sum of squared Euclidean distance between two arrays
for m' = 0 to m
for k' = max(0, m-m') to min(m', k)
Take the problem of the first m' items of X and the first k' items of Y. Find the value of the smallest sum, and whether X[m'] is in that sum.
The optimal subset of the first m' items of X is either the best subset of the first m'-1 items of X matching the first k' items of Y, or the best subset of the first m'-1 items of X matching the first k'-1 items of Y, with X[m'] and Y[k'] added.
Note that sets and subsets are not sorted. If you want the indexes in arbitrary order, sorting X and Y first should work.