Problem statement:
There are M bones to distribute amongst N dogs. Each dog i requires b_i bones. If it recieves less than b_i bones, it will have an anger of (deficit of bones)^2.
Given the number of bones M, number of dogs N and each dogs individual bone requirement b_i, print the minimum possible sum of anger of dogs.
Example:
M=5, N=3
bones = [1,3,2]
Output : 1
give 0th dog 0 bones, (anger 1^2=1), give 1st dog 3 bones (anger=(3-3)^2=0) and 2nd dog 2 bones (anger=(2-2)^2=0). Hence total anger is 1.
Constraints : 1<=M<=10^10, 1<=N<=10^6.
I tried a dp approach for this problem with index and number of bones remaining as state. however the tc is O(N * M * M) which gave tle.