QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 64 MB 満点: 100

#15587. Optimal Cutting

統計

Members of the HURRICANE group recently went to a factory for an internship, where they encountered the following problem. They need to cut a part out of a template. Both the template and the part are given convex polygons, and the position of the part within the template is already fixed. We know that for the part, except for adjacent sides, the intersection point of the extensions of any two sides lies outside the template.

Due to the factory's processing constraints, each cut must be made along the line containing one of the sides of the part. This cut divides the template into two parts; the part containing the component is kept, and the cutting process continues. The cost of each cut is defined as the length of the cut mark on the template. How should the cutting order be chosen to minimize the total cost?

Input

The input includes two parts, describing the shape and coordinates of the template and the part, respectively:

  • The first line contains the number of vertices of the template $n$ ($3 \le n \le 2000$). The following $n$ lines each contain two real numbers $x, y$ ($-1,000,000 < x, y < 1,000,000$), representing the coordinates of the template vertices in counter-clockwise order.
  • The $(n+2)$-th line contains the number of vertices of the part $m$ ($3 \le m \le 2000$). The following $m$ lines each contain two real numbers $x, y$ ($-1,000,000 < x, y < 1,000,000$), representing the coordinates of the part vertices in counter-clockwise order.

Output

The output should contain only a single integer, which is the minimum cost rounded to the nearest integer.

Examples

Input 1

4 
0 0 
0 3 
3 3 
3 0 
4 
1 1 
1 2 
2 2 
2 1

Output 1

8

Input 2

4 
0 0 
3 0 
3 3 
0 3 
4 
0 0 
2 0 
2 3 
0 3

Output 2

3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.