Maximize area in $1000\times 1000$ array using two non-overlapping squares centred at two points, p1 and p2. Maximize area in $1000\times 1000$ array using two non-overlapping squares centered at two points, p1 and p2. The following conditions must be met:


*

*The area (square 1 area + square 2 area) should be a maximum for the given points, p1 and p2

*The squares must be centered on their respective point (i.e. must have area $n^2$, where n is odd)

*The squares cannot overlap

*The squares must remain within the $1000\times 1000$ grid


Note: The squares do not need to be the same size.
I solved the equivalent 1D case, but the 2D case seems quite a bit more challenging. Has anyone solved this before, or have any suggestions/ideas for solving such a problem?
This is my first post on here, so let me know if I'm doing it wrong... Thanks!
 A: Some thoughts:


*

*obviously if the points are closer to the edge than they are to each other, then the maximum will involve both squares touching the edge.

*otherwise, the two squares will have a total edge length equal to twice their centers' maximum axis distance apart:  Two points that are 300 distance apart can be 599x599 and 1x1, or 299x299 and 301x301, or some other combination that sums the same way.


If their distance apart is $d$, and the edge length of one square is $x$, then we have: $z=2d-x$, and the total area is $x^2+z^2=x^2+4d^2-4xd+x^2=4d^2-4xd+2x^2$.
Since $d$ is held constant, we have an upward-pointing parabola.  Thus, the farther we can get from the vertex, the better.  So where's the vertex?
Well, it's at $-b/2a=4d/4=d$.  So the lowest area is when the two squares are equal in size!
Thus, the highest area picks the largest square we can fit around one of the points without either 1. leaving the area or 2. overlapping the other point.  Pick the point that gives the larger of these to put the large square around, and you win.
