Recently, I came across this problem and I was intrigued as to whether 1) I could categorise this type of problem to a specific name or 2) what the best way to solve this problem was. It's a bit finicky so bear with me as I'll try to explain it the best I can (apologies in advance for the poor drawing).
You are given an n x n matrix which represents plots of soil. Each entry has a numeric value which represents the amount of water required to make that plot fertile. You are able to choose a specific co-ordinate about which the rain falls (with intensity I) and the area of rainfall depends on the parameter d (which is always even). Big d means more area..
Here comes the finicky part.
The rain falls in the way illustrated in the image below. The outskirt (represented by the dotted green lines) receive half the rainfall ( I/2 ) to their counterpart. So in this case, it would receive 4 mm. Hence, by deciding to pour rain about the point (3,3) there would be 7 plots of soil on the boundary (7 plots which are less than or equal to 8 / 2 = 4) and 10 plots of soil on the inner (10 plots which are less than or equal to 8) leading to 17 plots of soil in total that become fertile.
The question asks, given the arguments for (n x n: 2d int array, d: int, I: int), what is the maximum number of plots of soil that can be made fertile?
n.b. there are no restrictions on where the co-ordinates may be i.e. it can be on the edge of the terrain.
I solved it in the following way:
Basically brute force but with some efficiency tweaks.
Efficiency tweak 1: Based on the value of d, there is a limit [d * (d / 2 + 1)] as to how many plots of soil it encompasses. If any point satisfies the max then stop searching.
Efficiency tweak 2: If the value of d is 10, for example, then the radius of that will be 5 meaning at best it will completely cover sqrt(5) by sqrt(5) inside the inner area. In other words, it will cover at most 2 x 2 completely and hence, we can start searching from the point (2, 2) instead of from (0, 0) which will unnecessarily water vacant land. Similarly, we can end searching at the diagonally opposite point which will be (n - 2, n - 2).
This solution feels non-optimal because as d and n x n get bigger, there is a lot of overlap in the land being calculated.