Extra Corners#540

Solution

If , the removed corner squares do not overlap in their interiors. At each corner, two boundary segments of length disappear and two new segments of the same length appear, so the total perimeter remains .

If , the removed squares touch at a single point, and two square pieces of side length n-k remain. We count the entire boundary of each piece. Their total perimeter is 8(n-k)=4n, which agrees with the second example.

If 2k>n, the remaining paper consists of two separate squares of side length n-k. Their total perimeter is 2\cdot4(n-k)=8(n-k).

Thus the answer is when 2k\le n, and 8(n-k) otherwise.

Complexity

time and extra memory.