#P5977. Optimal Fence Construction
Optimal Fence Construction
Optimal Fence Construction
In a 1000×1000 region there are n fixed points and m trees. You want to build a fence that protects some trees. The fence is built by choosing a subset of the fixed points that forms a convex polygon (the polygon's vertices are exactly the chosen points and they are in convex position). A tree is considered protected if it lies inside or on the boundary of the fence. The cost to build such a fence is computed as:
[ \text{Cost} = (#\text{ of fixed points chosen})\times20 + (#\text{ of trees not enclosed})\times111. ]
You may also choose not to build any fence, in which case the cost is m × 111 (since no trees are fenced). Your task is to determine the minimum possible cost.
Note: It is always possible to choose no fence. When building a fence, you must select at least 3 fixed points to form a polygon. If a set of fixed points is not in convex position (i.e. one or more points lies strictly inside the convex hull of the others), then you should instead consider using only the points on the convex hull (which is always a valid fence with lower cost).
inputFormat
The first line contains two integers n and m (the number of fixed points and the number of trees, respectively).
The next n lines each contain two integers x and y, representing the coordinates of each fixed point.
The following m lines each contain two integers x and y, representing the coordinates of each tree.
outputFormat
Output a single integer — the minimum possible cost.
sample
4 4
0 0
0 10
10 10
10 0
1 1
5 5
5 6
9 9
80