TITLE: Write $n^2$ real numbers into $n \times n$ square grid
QUESTION [9 upvotes]: Let $k$ and $n$ be two positive integers such that $k<n$ and $k$ does not divide $n$. Show that one can fill a $n \times n$ square grid with $n^2$ real numbers such that sum of numbers in an arbitrary $k \times k$ square grid is negative, but sum of all $n^2$ numbers is positive.
Source: Homework
My idea: I presented $n = mk + r$ and write $-k^2$ into each square with coordinate of the form $(ik, jk)$ where $i, j$ are positive integers and 1 in another squares. Then the sum of each $k \times k$ square is $-1$ and sum of $n^2$ numbers is $n^2 - m^2(k^2+1)$. But this doesn't work for large $m$.

REPLY [3 votes]: Here's an answer to show that in fact the OP's original idea works, if the numbers are chosen correctly.
Let our matrix take values $b-a$ at indexes $(ik,jk)$ and $b$ elsewhere, with $n$ factored as $n=mk+r$. Then the sum across a $k\times k$ submatrix is $k^2b-a$, and the sum across the whole $n\times n$ matrix is $n^2b-m^2a$. The constraints to satisfy are thus $n^2b>m^2a$ and $k^2b<a$. This implies $m^2k^2b<m^2a<n^2b$, so $mk<n$ implies $b>0$. Dividing through by $m^2b$, we get
$$k^2<\frac ab<\frac{n^2}{m^2},$$
and we can feel free to choose $b=2m^2$ and $a=n^2+m^2k^2$ (the midpoint) or any other solution which satisfies the inequality. The OP's choice used $b=1$ and $a=k^2+1$, which satisfies the first inequality, but the second inequality in the worst case has $r=1$ so $\frac nm=k+\frac1m$ and $\frac{n^2}{m^2}=k^2+2\frac km+\frac1{m^2}$, so the $+1$ is a bit too generous and is undercut for large $m$. (This can also be taken as a proof that a sufficiently large integer solution cannot take $1$ for the "background" value $b$.)