I wrote this code for solving the Chef and Mover Problem. I tested it against all the inputs along with some other inputs, I tried submitting my code using Brute force method which showed TLE, so I again tried implementing it another way, which worked for inputs but the code chef compiler showed 2 AC and 4 WA, can somebody please help me to understand where did I go wrong.. Here is the code
asked 18 Aug '17, 15:39

First of all find the average of all the numbers in the array, which will tell you how much you have to decrease/increase a specific no. to get all the digits same in the array. Now if the average Comes out to be floating, print 1 and break , i.e not possible for array to have all the digits same. else: use a for loop till nd and for each element not equal to average, increase/decrease it to the shift required and consecutively decrease/increase the no. at index (i+d). In the end check whether if only one element remains in the set of array which should be equal to the average we calculated. Check my solution Here. answered 18 Aug '17, 20:26
Can you help with this code then, this is the one I wrote first, but this one Gave TLE, in this one I found the average first
(18 Aug '17, 21:14)
Instead of increasing your arr[i] by 1 until it reaches req, why dont you increase it directly to the req value. you can skip your unnecessary loop time waste here. I hope it helps.
(18 Aug '17, 21:21)
but then, if I would increase it directly, then how to keep track of no. of moves then?
(18 Aug '17, 22:09)
Number of moves= (new value old value). OR, we know that we only need to keep value=avg on that index. So ultimately no. of moves done is "a[i]  avg"
(18 Aug '17, 22:10)
