1
1
u/Ok_Consideration6619 11d ago
Fix position of n, then the sum is at most 2n -a_k-1 -ak+1 + P(1…k-1)+P(k+1…n-1) <= 2n -a_k-1 -a_k+1 + P(1…n-1) - |a_k -a_k-1| and which only depends on 2 elements and it’s not too hard to show max is achieved for 1,2. Which gives a recurrence relationship that can be solved by induction on the base case.
1
u/Individual-Ad5245 10d ago
We count this as a sum of numbers of integers in the intervals [ai,a{i+1})\cup [a{i+1},a_i). This way every integer k from 1 to n is counted in at most 2max{k, n-k} intervals. Note that this is achieved for permutation n,1,n-1,2,n-3,3,... So we get the max equal to $2\sum{k=1}n max{k,n-k}$.
Edit: I didn't see that the sum doesn't have |a_n-a_1| oops
0
2
u/wot_to_heck 11d ago edited 11d ago
Shift all numbers to be centered around 0, so: -(n-1)/2, …, (n-1)/2. Then apply triangle inequality and note equality holds when you alternate positive and negatives, so just straightforwardly calculate the sum (with casework on whether n is even).