Nuclear - Hard
In the Σ-world, there are 1 <= N <= 1,000,000 nuclear reactors, each one has a power index 1 <= Pi < 1,000,000,000. There are exactly N spots on the planet where these reactors can be situated. Additionaly, all these spots lie on a single line. A recent study showed that these reactors have the best combined efficiency when they are arranged such that the sum of absolute differences of powers of every pair of adjacent reactors is minimal. Nuclear reactors are expensive to move so Σ-lets want to know the mimimal number of reactors that need to be resituated to achieve maximum efficiency. Note: The line does not wrap around, it is not a circle. There are N-1 adjacent pairs.
4
3
1
3
6Sample output:
2Two reactors (the first and second) should be swapped. The sum then becomes 2+0+3 = 5.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.