The maximum value of f is 1.
Firstly, we prove that f≤1. It suffices to show that
ni=1∑n(j=1∑maij)2+mj=1∑m(i=1∑naij)2≤(i=1∑nj=1∑maij)2+mni=1∑nj=1∑maij2,
or(i=1∑nj=1∑maij)2+mni=1∑nj=1∑maij2−ni=1∑n(j=1∑maij)2−mj=1∑m(i=1∑naij)2≥0,
or1≤p<s≤n1≤q<r≤m∑(apq+asr−apr−asq)2≥0.
So f≤1, and when all of aij are equal to 1, f=1.
The minimum value of f is mn+min{m,n}m+n.
To prove f≥mn+min{m,n}m+n, without loss of generality, we assume n≤m. Hence it is sufficient to prove that
f≥mn+nm+n1◯
Let
S=m+nn2(m+1)i=1∑nri2+m+nmn(m+1)j=1∑mcj2
−(i=1∑nj=1∑maij)2−mni=1∑nj=1∑maij2,
where ri=∑j=1maij, 1≤i≤n, cj=∑i=1naij, 1≤j≤m.
Now 1◯⇔S≥0. Consider Lagrange's equation.
(i=1∑naibi)2=(i=1∑nai2)(i=1∑nbi2)−1≤k<l≤n∑(akbl−albk)2
Put ai=ri, bi=1, 1≤i≤n. Then
−(i=1∑nj=1∑maij)2=−ni=1∑nri2+1≤k<l≤n∑(rk−rl)2,
and
S=m+nmn(n−1)i=1∑nri2+m+nmn(m+1)j=1∑mcj2=−mni=1∑nj=1∑maij2+1≤k<l≤n∑(rk−rl)2=m+nmn(n−1)j=1∑mi=1∑naij(ri−aij)2+m+nmn(m+1)i=1∑nj=1∑maij(cj−aij)2+1≤k<l≤n∑(rk−rl)2.
Since aij≥0, ri≥aij, cj≥aij, so S≥0.
When a11=a22=⋯=amn=1 and the other aij=0, the minimum value of f is mn+nm+n.
With the above arguments, we conclude that the maximum value of f is 1 and the minimum value of f is mn+min{m,n}m+n.