Cutting with Lasers
InterviewTime limit1sMemory limit1024 MB
Given a closed path of axis-parallel laser cuts on a sheet, find the area of the largest enclosed piece that does not touch the sheet edge.
- Level
Medium5 of 10
- Topics
- BFS, Matrix, Implementation
- Solved
- No attempts yet
Problem
A laser cutting machine for wood sheets has a laser head that can move in only two directions, horizontal and vertical. You have been hired to be part of the testing team for the machine.
One of the tests consists of programming the machine to perform a non-empty sequence of consecutive cuts that starts and ends at the same point. Each cut in the sequence, except the first, starts at the point where the previous cut ended. No cut touches the edge of the sheet. Figures (a) and (b) below show two examples of cutting sequences, with 8 and 14 cuts, respectively.

Your boss asked you to find the area of the largest piece produced by the sequence of cuts, leaving out the piece attached to the edges of the sheet. Only pieces contained in the polygon formed by the cut lines are counted. Figures (c) and (d) show the largest pieces produced by the cuts in figures (a) and (b).

For illustration, figures (e) and (f) show the discarded piece, which contains the edges of the wood sheet, for the cut sequences in figures (a) and (b).

Input
The first line contains an integer , the number of cuts (). The second line contains two integers and , the initial position of the laser head (, ). Each of the next lines contains two integers and , the final position of cut (, , ). It is given that . All positions in the input are distinct, except the first and the last positions.
Output
Print a single line containing one integer, the area of the largest piece produced by the sequence of cuts.