(i, j) stands an apple tree bearing |i| + |j| apples.
You fence off a square plot with sides parallel to the axes, centered at (0, 0). Every tree inside the plot or on its border is yours.
Return the smallest perimeter of such a plot that holds at least apples apples.apples=12 → 8
The plot from -1 to 1 on both axes: 4 edge trees with 1 apple and 4 corner trees with 2, for 12 in total. Side 2, perimeter 8.
apples=61 → 24
A plot with side 4 gives 60 apples, one short, so the side must be 6 and the perimeter 24.
apples=1 → 8
apples=12
8
Run checks the first 3 tests in your browser. Submit checks all 64 tests on the server, hidden ones included.