luogu#P5100. [JOI 2017 Final] 足球 / Soccer

[JOI 2017 Final] 足球 / Soccer

Problem Description

This problem is translated from JOI 2017 Final T4「サッカー / Soccer」.

The sentence “Assume that while the ball is rolling it can pass through other players” was added by me for strictness without changing the original testdata. The original statement did not mention this. If the ball stops when it hits other players, the solution seems to be different.

You are the manager of a famous soccer club in the JOI league.

The club has NN players, numbered 1N1 \ldots N. The players train hard every day, aiming for the league championship. The soccer field can be seen as a rectangle with width WW meters and height HH meters. The width is parallel to the east-west direction, and the height is parallel to the north-south direction. If from a point you go north ii meters and then go west jj meters and arrive exactly at the northwest corner of the field, then this point can be represented by coordinates (i,j)(i, j).

After training, you need to collect the practice soccer ball. When you start collecting, all players are on the field. Player i (1iN)i \ (1 \leqslant i \leqslant N) is at (Si,Ti)(S_i, T_i), and the ball is at the feet of player 11. You are standing together with player NN at (SN,TN)(S_N, T_N), ready to collect the ball. You will collect the ball only when the players pass the ball to (SN,TN)(S_N, T_N).

You can give instructions to the players, but some operations will increase a player’s fatigue. A player cannot perform multiple operations at the same time.

You can instruct the player who currently controls the ball to perform the following operations:

  • Kick: Choose one of the four directions (east, west, south, north), and specify a positive integer pp. The player kicks the ball exactly pp meters in the chosen direction. Assume that while the ball is rolling it can pass through other players. The player does not move, and automatically stops controlling the ball. The player’s fatigue increases by A×p+BA \times p + B.
  • Dribble: Choose one of the four directions (east, west, south, north). The player moves with the ball by 11 meter in the chosen direction. The player still controls the ball. The player’s fatigue increases by CC.
  • Stop controlling the ball: The player’s fatigue does not change.

You can instruct a player who does not control the ball to perform the following operations:

  • Move: Choose one of the four directions (east, west, south, north). The player moves by 11 meter in the chosen direction. The player’s fatigue increases by CC.
  • Take control of the ball: The player can take control only if the ball is exactly at the player’s position, and no other player is controlling the ball. The player’s fatigue does not change.

Players and the ball may move outside the field, and there may be multiple players at the same position.

After a day of training, the players are very tired. You want to know the minimum possible value of the sum of fatigue increases of all players during the process of collecting the ball.

Input Format

The first line contains two integers H,WH, W, separated by spaces.
The second line contains three integers A,B,CA, B, C, separated by spaces.
The third line contains one integer NN.
In the next NN lines, line i (1iN)i \ (1 \leqslant i \leqslant N) contains two integers Si,TiS_i, T_i, separated by spaces.
The meanings of all input values are described in the statement.

Output Format

One line with one integer, representing the minimum sum of fatigue increases of all players during the process of collecting the ball.

6 5
1 3 6
3
1 1
0 4
6 5
26
3 3
0 50 10
2
0 0
3 3
60
4 3
0 15 10
2
0 0
4 3
45
4 6
0 5 1000
6
3 1
4 6
3 0
3 0
4 0
0 4
2020

Hint

Sample Explanation 1

In this sample, the field, the players, and the ball are in the state shown in the figure. In the figure, the hollow circles with black outlines represent players, the solid circle represents the ball, and you are at (6,5)(6,5).

An optimal solution is as follows:

  1. Player 11 kicks the ball 33 meters to the east. The fatigue increases by 1×3+3=61 \times 3 + 3 = 6, and the ball moves to (1,4)(1,4).
  2. Player 22 moves 11 meter to the south. The fatigue increases by another 66.
  3. Player 22 starts controlling the ball.
  4. Player 22 dribbles 11 meter to the east. The fatigue increases by another 66.
  5. Player 22 kicks the ball 55 meters to the south. The fatigue increases by 1×5+3=81 \times 5 + 3 = 8, and the ball moves to (6,5)(6,5).

At this point, the total fatigue increase is 6+6+6+8=266 + 6 + 6 + 8 = 26. There is no better plan.

Sample Explanation 2

In the optimal solution, kicking is not necessary.

Sample Explanation 4

Note that in this sample there are multiple players at the same position.

Constraints and Hints

For 5%5\% of the data, N=2N = 2.
For another 30%30\% of the data, N1000N \leqslant 1000 and A=0A = 0.
For all data, 1H,W5001 \leqslant H, W \leqslant 500, 0A,B,C1090 \leqslant A, B, C \leqslant 10^9, 2N1052 \leqslant N \leqslant 10^5, 0SiH0 \leqslant S_i \leqslant H, $0 \leqslant T_i \leqslant W \ (1 \leqslant i \leqslant N)$, (S1,T1)(SN,TN)(S_1, T_1) \neq (S_N, T_N).

Translated by ChatGPT 5