Given a list of N lists, each containing M positive integers, and a separate list of M positive integers (target values), return a list of N scalars (integers with a value of 0 or more) that correspond to each list in the lists of lists, such that when each value in a list is multiplied by it's scalar, and the values at each index of each list are added together to make one final summed list, the sum of the absolute difference between each value in the summed list and the target list is minimized. If there are multiple possible outputs of equal absolute difference for a given input, output any single answer.
The solution with the fastest algorithm (by running time complexity) wins.
Examples:
Input:
Lists: [[1,2], [2,1]]
Target: [9,9]
Output:
[3, 3]
---------- ---------- ----------
Input:
Lists: [[3,9,2,1], [7,1,2,3], [2,3,8,1]]
Target: [60, 70, 50, 60]
Output:
[6, 5, 4]
---------- ---------- ----------
Input:
Lists: [[9, 7, 8], [9, 4, 12]]
Target: [176, 68, 143]
Output:
[6, 8]
Example of Answer Corectness Checking:
Input:
Lists: [[9, 7, 8], [9, 4, 12]]
Target: [176, 68, 143]
Output:
[6, 8]
6 * [9, 7, 8] = [54, 42, 48]
8 * [9, 4, 12] = [72, 32, 96]
[54, 42, 48] + [72, 42, 96] = [126, 84, 144]
summed difference:
abs(176 - 126) + abs(68 - 84) + abs(143 - 144)
= 50 + 16 + 1
= 67
(minimize this number)
Lists: [[2], [4]], Target: [12]
\$\endgroup\$