M adjacent integers M1,…,MN are inserted in a circle
the following operation can be done M-1 times
pick 2 adjacent nos. and sum them up and store it in a variable.
delete picked numbers and replace it with that single variable number in the circle.
What is the minimum value of that variable?
Isn't the answer always equal to the sum of all the numbers?
1. You have a sequence of numbers.
2. If the sequence has less than two elements, you're done.
3. Otherwise, remove any two of its elements, add them, and put back the result of the addition.
4. Go to step 2.
Following this algorithm, regardless of which two numbers are picked each time on step 3, the final result will necessarily be either an empty sequence or a sequence with a single element that's the sum of all the elements of the original sequence.
One "operation":
* pick 2 adjacent nos. and sum them up and store it in a variable
variable = 10+8. variable == 18
* delete picked numbers and replace it with that single variable number in the circle
circle: 18 9
Second "operation":
* pick 2 adjacent nos. and sum them up and store it in a variable
variable = 18 + 9. variable == 27
* delete picked numbers and replace it with that single variable number in the circle
circle: 27
Result: 27
The result would be different, if the instructions would say that the variable is 0 at start and you add pairwise sum to the variable.
Furthermore: "operation can be done M-1 times". "Can", not "have to". Okay, I'll do the operation 0 times. Nothing is stored into variable. That must be the hands down minimum (unless the circle contains negative values).
@keskiverto, @minimum, didn't write the problem correctly as @lazybot told. I think In this problem, you have to do the "operations" till you have only 1 number left in the array. That's why here we have to do these operations.
Also, you wrote the second operation wrong. it's 18+(18+9).i.e 18+27=45. which is not the minimum value(which is 44).
If this is a Codechef problem, you should know that the Codechef adjudicators are aware of this forum, and that people use it to cheat on their contests. If you use this forum to try and cheat, you run the risk of being disqualified.
No. What I wrote was valid according to the OP instructions. One must be exact with computers. They do not guess your intentions. They do exactly what they are told.