Define the numbers written to each grid as shown in the table 1. I can assume that A1 is the minimum and A4 is the maximum in A1,A2,A3,A4, and that B1 is the minimum and B4 is the maximum in B1,B2,B3,B4, by rearranging rows and columns appropriately. Now m≤A4−A1, m≤B4−B1, so
m≤2(A4−A1)+(B4−B1)=21(a4,4−a1,1)+21(a4,4+a4,2+a4,3+a2,4+a3,4−a1,1−a1,2−a1,3−a2,1−a3,1)≤21(16−1)+21(16+15+14+13+12−1−2−3−4−5)=35
And there exists a way of writing if m=35 (table 2). So the maximum m is 35. This is table 1.
| a1,1 | a1,2 | a1,3 | a1,4 | A1 |
|-----------|-----------|-----------|-----------|-------|
| a2,1 | a2,2 | a2,3 | a2,4 | A2 |
| a3,1 | a3,2 | a3,3 | a3,4 | A3 |
| a4,1 | a4,2 | a4,3 | a4,4 | A4 |
| B1 | B2 | B3 | B4 | |
This is table 2.
| 1 | 2 | 5 | 11 | 19 |
|---|---|---|----|----|
| 3 | 6 | 7 | 12 | 28 |
| 4 | 8 | 9 | 14 | 35 |
|10 |13 |15 | 16 | 54 |
|18 |29 |36 | 53 | |