LaserTag

View as PDF

Submit solution


Points: 1
Time limit: 1.5s
Memory limit: 256M

Problem types

LaserTag

Ozan loves playing LaserTag. He invented a specific version of the game, called Turn Based LaserTag. Now it's your turn to play!

In each turn, one of the player becomes the shooter, and others become targets. Since it's your turn, you'll become the shooter. The game will be played in a rectangular shaped room.

There will be \(N\) targets, and your mission is to shoot all of them. Unlike the regular game, you need to use a reflection point while shooting. A reflection point is a mirror like object, which can reflect laser shots. There will be \(R\) reflection points, and you need to use exactly one reflection point to shoot. However, shooting with different reflection points, might give you different scores.

Rules

You will be playing in a rectangular room with the shape \(m \; x \; n\). The distance between the west and east edges of the room will be \(m\), and the north and south edges will be \(n\). You will be always shooting from the south edge.

During the game, you can assume that the targets will appear one by one, so the existence of a target will not interfere with other targets.

The reflection points will be on the west and east edges. Note that they are point like mirrors, they have no length. You can assume that the reflection points will reflect the shots acting as a mirror. The mirror's normal can be thought a line parallel to the west east axis.

Your mission is to shoot all of the targets. While shooting, you need to select the reflection point that gives you the most score. However, there will be cases that you cannot complete your mission, since there might not be an available reflection point.

Finally, you can assume that the west-south corner will be \((0, 0)\), and the \(x\) coordinate will increase on south edge, and \(y\) coordinate will increase on west edge.

Input

For the first line of the input, you will be given five integers N R m n x_p, the number of targets, the number of reflection points, the length and the width of the room, and your location (which will turn into \((x_p, 0)\)) respectively.

For the next \(N\) lines, you will be given two integers x_i y_i, the \(x\) and \(y\) coordinates of the target, respectively.

For the next \(R\) lines, you will be given three integers x_r y_r s, the \(x\) and \(y\) coordinates of the reflection point, and the score you will receive using the reflection point, respectively. Remember that, the \(x\) coordinate will either equal to \(m\) or \(0\).

  • \(0 < N \leq 3 * 10^3\)
  • \(0 < R \leq 10^5\)
  • \(2 \leq m, n \leq 10^{10}\)
  • \(0 < x_p, x_i < m - 1\)
  • \(0 < y_r, y_i < n - 1\)
  • \(x_r = 0\) or \(x_r = m\)
  • \(0 < s \leq 10^2\)

You may use the epsilon value \(10^{-6}\) for float comparison.

Output

If you can successfully complete the mission, print the total score you receive during your mission. Otherwise, print -1.

Example

Input 1:

1 1 6 5 3
5 4
6 3 5

Output 1:

5

Input 2:

1 3 3 5 1
1 2
3 1 56
0 1 93
3 2 100

Output 2:

93

Image of Input 1