Suppose a1<a2<⋯<an . Then on each interval (ak,ak+1),
f(x)=∑i=1k(ai−x)+∑i=k+1n(x−ai)=(n−2k)x+∑i=1kai−∑i=k+1nai
Thus, f(x) is decreasing on (ak,ak+1) as long as n−2k>0, i.e. k<2n , increasing as soon as k>2n.
We see there are two cases:
If n is odd; n=2p+1, there is a unique minimum, attained at the middle point ap+1 , and its value is:
f(an+1)=−a1−⋯−an+an+2+⋯+a2p+1.
If n is even: n=2p, the function attains its minimum on the middle interval [ap,ap+1] and its value is:
−a1−⋯−ap+ap+1+⋯+a2p.
Comments