How to approach below problem?
Given an array of integer, the squared sum is defined as the sum of squares of all elements. Given that the cost of changing element x of array to y is (x-y)^2 and element once changed cannot be changed again. Change the given array elements to get the desired squared sum.
For example :
Suppose array is {3,3,1} and desired squared sum is 6. Than we can change 3 to 1 and next 3 to 2 so the array becomes {1,2,1} or {2, 1, 1} and 1^2 + 2^2 + 1^2 = 6 i.e desired sum and the cost of change is (3-2)^2 + (3-1)^2 = 5.