GOC2014 - DMS Mathematica Explain the solution?

The answer seems to be (n*n)/2 - 1 .

For N =5 , ans = 11 ;

But I think it should be 10;
permutation 5 1 4 2 3
4 + 3 + 2 + 1 = 10

If I am wrong please explain ?

f([4, 1, 5, 2, 3]) = |4 - 1| + |1 - 5| + |5 - 2| + |2 - 3|
= 3 + 4 + 3 + 1
= 11

1 Like

Sorry couldn’t get the ques… what if the sequence is {109,1,2,3,4}?

Actually the sequence consist of all numbers from 1 to n and n <= 10 ^ 9 .
We need to permute the sequence in such a manner in which the sum of abs value of differences of adjacent numbers should be maximum.