Let xk, for 1≤k≤40, be the number of integers i with 1≤i≤20 such that ai≥k. Let yk, for 1≤k≤40, be the number of integers j with 1≤j≤20 such that bj≥k. It follows from the problem statement that xk+yk is the number of elements of the set {1,…,40} which are greater than or equal to 40, which is just 41−k. Note that if 1≤i,j≤20, and 1≤k≤40, then min(ai,bj)≥k if and only if ai≥k and bj≥k. So for a fixed k with 1≤k≤40, the number of pairs (i,j) with 1≤i,j≤20 such that min(ai,bj)≥k is equal to xkyk. So we can rewrite ∑i=120∑j=120min(ai,bj)=∑k=140xkyk. Since xk+yk=41−k for 1≤k≤40, we have xkyk≤⌊241−k⌋⌈241−k⌉ by a convexity argument. So ∑i=120∑j=120min(ai,bj)≤∑k=140⌊241−k⌋⌈241−k⌉=5530. Equality holds when (a1,…,a20)=(2,4,…,38,40) and (b1,…,b20)=(1,3,…,37,39).