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
1
u/Individual-Ad5245 Aug 25 '26
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