QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#479. The Invasion

الإحصائيات

And so it has come - the Triangles have invaded Byteotia! Byteotia lies on an island, occupying its entire surface. The shape of the island is a convex polygon (i.e. a polygon whose each inner angle is smaller than 180°). A certain number of software factories are located in Byteotia, each of which generates constant gains or losses.

The Triangles have decided to occupy such a part of Byteotia which:

  • is a triangle-shaped area, the vertices of which are three different vertices of the polygon-island,
  • brings the largest income i.e. the sum of all gains and losses generated by factories within the occupied area is maximal.

We assume that a factory located on the border or in the vertex of occupied area belongs to that area. A territory which contains no factory brings, obviously, a zero income.

Byteasar, the King of Byteotia, is concerned by the amount of losses the Triangles' invasion could generate. Help him by writing a programme which shall calculate the sum of gains and losses generated by factories which the Triangles wish to capture.

Write a programme which:

  • reads a decription of Byteotia's shape and the locations of factories from the input file,
  • determines the maximal value of sum of all gains and losses generated by factories within a triangle, whose vertices are three different vertices of the polygon island,
  • writes the outcome to the output file.

Input

The first line of the input file contains a single integer $n$ ($3 ≤ n ≤ 600$), denoting the number of vertices of the polygon-island. The following $n$ lines of the input contain two integers each $x_i$ and $y_i$ ($-10\,000 ≤ x_i,y_i ≤ 10\,000$), separated by a single space, denoting the coordinates $x$ and $y$ of consecutive vertices of the island, in a clockwise order. The $n+2$-nd line contains a single integer $m$ ($1 ≤ m ≤ 10\,000$), denoting the total number of factories. In each of the following $m$ lines there are three integers $x'_i$, $y'_i$ and $w_i$ ($-10\,000 ≤ x'_i,y'_i ≤ 10\,000$, $-100\,000 ≤ w_i ≤ 100\,000$), separated by single spaces, denoting: the coordinates $x$ and $y$ of the i-th factory and the gain (for $w_i ≥ 0$) or loss (for $w_i < 0$) this factory generates, respectively. Each factory is situated on the polygon-island i.e. within or on the border of it. Distinct factories may be located in the same place i.e. have the same coordinates.

Output

The first and only line of the output file should contain a single integer denoting the maximal value of sum of all gains and losses generated by factories within a triangle whose vertices are three different vertices of the polygon-island. Notice that it may happen that the outcome is a negative integer.

Example

Input

5
4 1
1 4
8 9
11 5
8 1
4
7 2 3
6 3 -1
4 5 3
9 6 -4

Output

5
problem_479_1.gif
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.