F - Fence the vegetables fail
Time limit: 3 s
Memory limit: 256 MiB
Languages: C, C++, Java, Pascal, ...
At the early age of 40, Alice and Bob decided to retire. After more than two decades working as examples for networking protocols, game theoretical books and several other texts, they were tired. To remain active, they decided to get into gardening.
Alice and Bob planted several vegetable plants in a huge field. After finishing, they realized that their plants needed protection from wild animals, so they decided to build a fence around them. The field is represented as the $XY$ plane, and each vegetable plant as a different point in it. A fence is represented as a polygon in the plane. However, not every polygon is a valid fence. The fence needs to be a single simple polygon with each of its sides parallel to one of the axes. Of course, the polygon should contain all the points representing vegetable plants. A fence too close to the plants or to itself could make it difficult to walk around, so each side of the polygon needs to be away from all plants and all non-adjacent sides.
Unfortunately, Alice and Bob subcontracted the construction of the fence to a nasty multinational. The company had a lot of lawyers on payroll, but no good fence designers, so they failed to comply to all requirements. They built a fence which is a simple polygon with sides parallel to the axes and whose sides are away from plants and itself. However, they forgot to make the fence contain all the plants! Alice and Bob want to assess the extent of the problem. Since not all plants are equally valuable to them, they want to know the total value of the plants that were left outside the fence.
The first line contains two integers $P$ and $V$, representing respectively the number of plants and the number of vertices of the polygonal fence ($1 \leq P, V \leq 10^5$). Each of the next $P$ lines describes a different plant with two integers $X_p$ and $Y_p$, indicating the coordinates of the plant $(−10^9 \leq X_p, Y_p \leq 10^9)$. The value of the $p$-th plant in the input is $p$, for $p = 1, 2, ..., P$. Each of the next $V$ lines describes a vertex of the fence with two integers $X_v$ and $Y_v$, indicating the coordinates of the vertex $(−10^9 \leq X_v, Y_v \leq 10^9)$. Vertices are given in counter clockwise order. Each of these points is an actual vertex of the polygon, that is, it is not collinear with its two adjacent vertices. The represented polygon is a simple polygon with each side parallel to an axis. No two plants are in the same position, and no plant lies on a fence’s side.