Without loss of generality, we can assume that a1≤a2≤⋯≤an, and denote dk=ak+1−ak, for k=1,2,…,n−1. Then we have:
* d1+d2+⋯+dn−1=d;
* ∣aj−ai∣=di+di+1+⋯+dj−1, for any i<j with i,j∈{1,…,n}.
Denote by nk the number of pairs (i,j), with 1≤i<j≤n, such that the interval [ak,ak+1] is contained in [ai,aj]. Then the conditions imply i≤k<k+1≤j, so there are k possible choices for i and n−k possible choices for j. Thus, nk=k(n−k). Consequently,
S=k=1∑n−1nkdk=k=1∑n−1k(n−k)dk.(1)
For any k∈{1,2,…,n−1}, we have k(n−k)≥n−1.
Indeed, k(n−k)≥n−1⟺kn−k2≥n−1⟺(k−1)(n−k−1)≥0, which holds for all k in the stated range.
From (1) and this, it follows that
S≥k=1∑n−1(n−1)dk=(n−1)d,
which proves the left inequality.
Equality holds for any n≥2 if and only if a1≤a2=a3=⋯=an−1≤an.
Using AM-GM inequality, we obtain k(n−k)≤4n2, for all k∈{1,2,…,n−1}. Therefore,
S=k=1∑n−1k(n−k)dk≤k=1∑n−14n2dk=4n2d,(3)
which proves the right inequality.
Since equality in the inequality k(n−k)≤4n2 holds when k=n−k, i.e., when n=2k (so n is even), from (3) we deduce:
* If dk=0 for all k=1,…,n−1, i.e., a1=a2=⋯=an, then equality holds for any n≥2.
* If there exists t∈{1,…,n−1} such that dt=0, then:
* If n is odd, the right inequality is strict.
* If n is even, equality holds only if t=n−t and dt=d, i.e., n=2t and a1=⋯=at≤at+1=at+2=⋯=a2t.
d=an−a1=(an−ak)+(ak−a1),for any 2≤k≤n−1.
We obtain:
S=1≤i<j≤n∑∣aj−ai∣=(an−a1)+k=2∑n−1((an−ak)+(ak−a1))++2≤i<j≤n−1∑∣aj−ai∣=(n−1)d+2≤i<j≤n−1∑∣aj−ai∣≥(n−1)d.
If n=2 or n=3, equality holds for any numbers a1≤a2, respectively a1≤a2≤a3.
If n≥4, equality holds if and only if a1≤a2=a3=⋯=an−1≤an.
Alternative solution for the right inequality.
We prove by induction the statement:
P(n):1≤i<j≤n∑∣aj−ai∣≤4n2⋅1≤i<j≤nmax∣aj−ai∣,
for all n≥2 and any real numbers a1,a2,…,an. Without loss of generality, assume a1≤a2≤⋯≤an.
Base cases:
P(2):a2−a1≤422⋅(a2−a1)⟺a2−a1≤a2−a1,
P(3):(a2−a1)+(a3−a2)+(a3−a1)≤432⋅(a3−a1)⟺2(a3−a1)≤49(a3−a1).
Assume P(n−2) holds for some n≥4. Using the notation from the statement and the fact that
d=an−a1=(an−ak)+(ak−a1),for any 2≤k≤n−1,
we deduce:
S=1≤i<j≤n∑∣aj−ai∣=(n−1)d+2≤i<j≤n−1∑∣aj−ai∣.
Denote
S′=2≤i<j≤n−1∑∣aj−ai∣,d′=an−1−a2.
Obviously, d′≤d. Since P(n−2) holds, we get S′≤4(n−2)2⋅d′. Therefore,
S=(n−1)d+S′≤(n−1)d+4(n−2)2⋅d′≤(n−1)d+4(n−2)2⋅d=4n2⋅d,
which proves P(n).
To determine when equality holds, observe that in P(2) equality holds for any a1≤a2, and in P(3) equality holds only if a1=a2=a3 (strict inequality otherwise if a1<a3).
It is clear that if a1=a2=⋯=an, then equality holds in P(n) for any n≥2.
Assume now that a1<an. From the previous inequality, equality in P(n) holds if and only if equality holds in P(n−2) and d′=d. Consequently:
* if n is odd, the inequality P(n) is strict;
* if n is even, say n=2t, equality holds if and only if a1=a2=⋯=at<at+1=at+2=⋯=a2t.