CBALLS - Editorial

1

4

8 9 9 9

@dushsingh1995 works fine for it, required ans =1, codeā€™s o/p =1.

@s1b2312

current_multiple = ((A[j] + i - 1)/i) * i;

This equation assigns multiple of i >= A[j] to variable current_multiple (To make non decreasing sequence).

How do you find out ā€œthe most common prime. that divides most number of elementsā€ ? Paste your code link also

in the editorialist solution,he has written in the if condition thatā€¦
if(required_no < arr[i])
{
ā€¦;
}
where the required_no is the previous index element and for the array to be non decreasing one,the required_no should obviously be lesser than the next elementā€¦Can someone please clarify the issue??

CodeChef: Practical coding for everyone Pls tell Why this gives WA I have calculated all primes using seive the I have calculated the total balls to be added to make each box balls divisible by that prime number and at the end I checked wether its non decreasing or not.

We can try each number between 1 and 10^310 
3
  as a potential GCD and change the array elements to its multiples in non-decreasing order.

I didnā€™t get this term.

Iā€™m new to DSA

I was thinking why canā€™t we just make the gcd of all numbers as 2 by making them reach their nearest even number
eg:
1
5
5 2 7 9 3
i made 5->6,2->6,7->8,9->10,3->10
cost = 1 + 4+1+1+7=14
my answer is coming 14
can somebody tell me where am I wrong or any test case that fails this

hey @dxbros
Thanks for sharing your doubt.

Your logic is wrong, here is a test case in which your logic fails.

4
3 9 14 21

Here the correct answer is 1, just change 14 ā†’ 15 and all numbers are in non-decreasing order and the gcd of all numbers is 3 which is greater than 1.

But according to your logic correct answer is 3.