This theorem is called Reordering Unevenness.
Proof made:
The simplest evidence is nasty than one of @ j_random_hacker .
Suppose a is sorted in ascending order.
Since each cell never touches more than one, one choice corresponds to a permutation s , and the total sum f(s) = sum(a[i]*b[s(i)], i=1..n)
Since the number of permutations is finite, there is at least one minimum.
Name s1 one of these minima. therefore f(s1)<=f(s) for all s
We can transform it into a permutation s2 with the same sum f(s1)=f(s2)<=f(s) as if a[i] = a[i+1] then b[s2(i+1)] >= b[s2(i)] (1) simply by sorting in decreasing order the auxiliary array b [s1 (k)] .. b [s1 (k + n)] of b, where a[k] = a[k+1] = .. q[k+n]
So f(s2) also minimal. We show that b(s2[k]) decreases from the contrary.
Suppose that there exists i , for example b[s2(i)] < b[s2(i+1)] (2)
due to (1), a[i]!= a[i+1]
so a[i] < a[i+1] (3)
so b[s2(i)] - b[s2(i+1)] < 0 (4) as a consequence of (2)
so a[i] - a[i+1] < 0 (5) as a consequence of (3)
in this case
a[i]*b[s2(i)]+a[i+1]*b[s2(i+1)]-(a[i]*b[s2(i+1)]+a[i+1]*b[s2(i)]) =a[i]*(b[s2(i)]-b[s2(i+1)])+a[i+1](b[s2(i+1)-b[s2(i)]) =(a[i]-a[i+1])(b[s2(i)]-b[s2(i+1)]) >=0 (because of product of two negative number because of (4) and (5) so a[i]*b[s2(i)]+a[i+1]*b[s2(i+1)] - (a[i]*b[s2(i+1)]+a[i+1]*b[s2(i)])>0 so a[i]*b[s2(i)]+a[i+1]*b[s2(i+1)] > (a[i]*b[s2(i+1)]+a[i+1]*b[s2(i)]) (6)
Set permutation s3 swapping i and i+1
s3(n) = i+1 if n = i i if n = i+1 s2(n) a[i]*b[s2(i)]+a[i+1]*b[s2(i+1)] > (a[i]*b[s3(i)]+a[i+1]*b[s3(i+1)]) and a[n]*b[s2(n)]=s[n]*b[s3(n)] for n!= i and n!=i+1 so f(s2)>f(s3)
So s3 is a better permutation than s2
There is a contradiction, therefore hypothesis (2) is false.
So, for all i b[s2(i)] < b[s2(i+1)] (2) false is used
So b[s2(i)] >= b[s2(i+1)] for all i
So s2 is such that b[s2(k)] is in decreasing order. Therefore, choosing a decrease for b gives an optimal result.
Using a similar proof, we can prove that the maximum product sum is specified by sorting a and b in ascending order.