We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Hi rmeghwal! If you are talking to me (it is not obvious from the comments arrangement), then I would like to point out, that my approach is not about making all zeros, but about making all the same. For that purpose I sort out the array first. After that, you see the following picture:

||||||||||||

The figure above is the visualization of numbers sorted in increasing order. After that you have to choose a pivot and increase the rest by either {1,2,5}, and repeat it utill all the numbers are the same. Intuitive step is to put pivot on greater number and adapt the smaller numbers to it and so on. Thus, we traverse the array, and at each iteration we choose current number as pivot, then adapt the prefix array to it. The total number of steps is the sum of steps required in each iteration. But sometimes encreasing the suffix array by either {1,2,5} can give the best result, due to discreteness of the steps. Therefore we need to select the minimum result among all options. You can check that out by yourself for correctness.
If you still think that you are doing the same, please show me your code.

Hi Zhassan,
can you please look into my code and say where i am doing wrong (apart from time complexity),

t1 = 1
t3 = 3
t5 = 5
for _ in range(int(input().strip())):
l = int(input().strip())
c = [int(f) for f in input().strip().split(' ')]
e = 0
count = 0
while(max(c)!=min(c)):
count += 1
mi = min(c)
mx = max(c)
d = mx-mi
if d >= t1 and d < t3:
e = t1
elif d >= t3 and d < t5:
e = t3
elif d >= t5:
e = t5
for i in range(len(c)):
if c[i] != mx:
c[i]+=e
print(count)
#print(c)

my answer - 933
expected - 10605
but still all are having same numbers of chocolates.

## Equal

You are viewing a single comment's thread. Return to all comments →

Hi, I also used the same, but I am unable to findout correct solution if input is 1 5 5 10 10.

After first step(value-min) : 0, 4, 4, 9, 9

step required to make all zero = 0+2+2+3+3=10

but if we try to do in this way like

Please let me know if I am doing something worng/incorrect.

Hi rmeghwal! If you are talking to me (it is not obvious from the comments arrangement), then I would like to point out, that my approach is not about making all zeros, but about making all the same. For that purpose I sort out the array first. After that, you see the following picture:

The figure above is the visualization of numbers sorted in increasing order. After that you have to choose a pivot and increase the rest by either {1,2,5}, and repeat it utill all the numbers are the same. Intuitive step is to put pivot on greater number and adapt the smaller numbers to it and so on. Thus, we traverse the array, and at each iteration we choose current number as pivot, then adapt the prefix array to it. The total number of steps is the sum of steps required in each iteration. But sometimes encreasing the suffix array by either {1,2,5} can give the best result, due to discreteness of the steps. Therefore we need to select the minimum result among all options. You can check that out by yourself for correctness. If you still think that you are doing the same, please show me your code.

Hi Zhassan, can you please look into my code and say where i am doing wrong (apart from time complexity),

t1 = 1 t3 = 3 t5 = 5 for _ in range(int(input().strip())): l = int(input().strip()) c = [int(f) for f in input().strip().split(' ')] e = 0 count = 0 while(max(c)!=min(c)): count += 1 mi = min(c) mx = max(c) d = mx-mi if d >= t1 and d < t3: e = t1 elif d >= t3 and d < t5: e = t3 elif d >= t5: e = t5 for i in range(len(c)): if c[i] != mx: c[i]+=e print(count) #print(c)

my answer - 933 expected - 10605 but still all are having same numbers of chocolates.

Hi! I think possible steps are {1,2,5} not {1,3,5} as you stated in the code. Please try one more time with that correction.

oh my bad, but still, no luck, but perhaps i found it, some wrong assumptions. thanks bro