Given numbers different from , () which are arranged randomly. We do the following operation: Choose some consecutive numbers in the given order and change their sign (i.e. ). What is the minimum number of operations needed, in order to make all the numbers positive for any given initial configuration of the numbers?
Problem 1546
Official solution
Given numbers different from , which are arranged randomly. We need to determine the minimum number of operations needed to make all the numbers positive. The operation allowed is to choose some consecutive numbers in the given order and change their sign (i.e., ).
1. Define a 'block':
A 'block' is a series of consecutive numbers with the same sign. For example, in the sequence , there are three blocks: , , and .
2. First Assertion:
To minimize the number of operations, we should always change the sign of all members of a block in one operation. If we do not do this, the number of blocks will either stay the same or increase.
Proof:
Consider two consecutive blocks, such as . If we do not change the entire block, we might end up with a situation like (the number of blocks stays the same) or (the number of blocks increases). Therefore, to reduce the number of blocks, we must change the entire block at once.
3. Second Assertion:
Let be the number of distinct blocks. It is always possible to decrease by 2 during one operation, and it is not possible to decrease by more than 2 during one operation.
Proof:
Consider the blocks as and . If , there exists a situation like (or with the signs inverted). If , we are almost finished. By changing the block , we arrive at , and decreases by 2. Changing several blocks at once does not decrease by more than 2 because the borders between the blocks within the series stay the same, and only the edges might merge with outside blocks, reducing by at most 2.
4. Minimizing the Number of Operations:
We want to reach in the fewest moves possible. We will only change whole blocks at a time. Changing a block on the edge decreases by only 1 at a time.
5. Maximal Number of Blocks:
Consider the situation where the number of blocks is maximal, . This means each number is a separate block.
- **Case 1: is even:**
The sequence is with blocks and blocks . In moves, will be equal to 2. Therefore, the minimum number of moves needed is .
- **Case 2: is odd:**
Using the same arguments, it will take moves to get to . However, we need all numbers to be positive. If the initial position has minuses on the edges, after moves, all signs will be negative. We need one additional move to make all numbers positive. Therefore, the minimum number of moves needed is .
The final answer is if is odd, and if is even.