The first thing we need to do is to make this into an equation. So assuming each well has the same amount of production, 4000 barrels / 20 wells = 200 barrels per well. Our current formula looks like this:

Production = Wells x Barrels per well (4000 = 20 x 200)

Lets say production = y and new wells = x

Since for every new well, we get a decrease of 5 barells

Production = (Wells + New wells) x (Barells per well - 5 barells per new well)

Mathematically, it looks like this:

Differentiate this function and equate it to 0 to find the maximum point, keeping in mind that x indicates # of new wells, not all wells.