how many minimum operations, you perform for this ??

You have n friends having some marbles initialy let ith friend has Mi marbles.you have infinite number of marbles. and you can perform folowing operation to equalize the marbles among your friends

1.you chose a friend , and give the others one marble except to chosen on.

2.you chose a friend , and give the others two marble except to chosen on.

3.you chose a friend , and give the others five marble except to chosen on.

tell minimum number of time you have to perform the above operations to equalize the marbles??plz help i realy can not get the right touch to such type questions.

example- let n=3 and initial marbles are

3 2 5

chosing 5

operate operation 2 (incresing others by two except chosen one 5)

5 4 5

chosing 5

operate opration 1 (incresing others by one except chosen one 6)

6 5 5

now chosing 6

operate opration 1 (incresing others by one except chosen one 6)

6 6 6

so minmum number of operations are three.

1 Like

Do u mean this Question
Contest link

2 Likes

My guess is one cant find the no. of operations barely using the no. of friends or their initial value.
Instead

  • Create a loop with counter variable=0
  • For each iteration find the difference bet. max. value and 2nd max. value
  • add 1 or 2 or 5 accordingly and increment the counter variable by 1
  • terminate the loop when there is no 2nd max. value.
  • Counter variable is your answer

Happy coding :slight_smile:

1 Like

@everyone : You should not discuss it here , it is from a live contest .
@admin : please delete this thread.

no i dnt know… but sm1 asked me this question…

i dnt think so…