How to make N numbers equal by addin only 1, 2 or 5? You can choose as many of N numbers and add 1, 2 or 5? Result is the minimum number of addition operation?

Example:; 2, 2, 3, 7 are numbers......... then adding 1 to all exept third will give 3, 3, 3, 8........ now add 5 to all exept last give 8 8 8 8......... so for this min number is 2

Pls suggest a solution strategy, which we can apply to any set of numbers

## Comments

Sort by:

TopNewestI think i got it......

1). find 1st minimum & 2nd minimum

2). calculate difference. between 1st & 2nd min

3).add the difference to all elements, except the 2nd minimum.

Repeat this till all elements become equal.

Example: 2,2,3,7

2nd min-1st min = 2-1 = 1

so, 3,3,3,8

2nd min-1st min = 8-3 = 5

so, 8,8,8,8

total steps=2

If the difference is not 1,2,5, then it sud be arranged in form of addition of 1,2,5.

example: 10=5+5, 9=5+2+2 – Akash Goyal · 4 years, 2 months ago

Log in to reply

The best solution uses 2 additions:

Your algorithm requires 4 additions:

I believe this is a fairly difficult problem. My best strategy at the moment is somewhere like this:

Determine the differences between each number and the maximum. Express the differences in as few terms as possible, and clear them up as efficiently as possible. This means applying as many 5s as possible to clear the maximum difference, then applying at most two 2s and one 1 for the remainders (\(0 = 0, 1 = 1, 2 = 2, 3 = 2+1, 4 = 2+2\); in all cases, only two 2s and one 1 are required).

I claim the above is at most 2 away from the best solution. I'm thinking of a better solution (or otherwise a rigorous proof that the above strategy is actually the best solution). – Ivan Koswara · 4 years, 1 month ago

Log in to reply