If a[i] is a non-decreasing sequence: a[1]≤a[2]≤…a[n], and
similarly b[i] is a non-decreasing sequence: b[1]≤b[2]≤b[n] then
we have that:
i∑a[i]b[i]≥i∑a[σ[i]b[i]
for any permutation σ∈Sn.
insight: the greedy strategy is the best. Think of b[n] as the max. number of times we are allowed to pick some a[i]. It is best to be greedy and pick the value maxia[i]b[n] number of times. maxia[i]=a[n]. Thus having a[n]b[n] will beat all others.
The proof strategy is to: show what happens for a transposition. Every
permutation can be broken down into transpositions and thus we are done.
Let S=∑ia[i]b[i]. Let T be S with us picking the value a[r]b[s] times,
and picking the value a[s]b[r] times. This gives
Since r<s we have b[r]≤b[s], hence b[r]≤b[s]<0. For the product
to be greater than zero, we need a[r]≤a[s], or a[s]≥a[r] when s>r.
Hence, for a transposition, we are done. Thus we are immediately done
for any permutation: