Master Mojtaba has downloaded a new game. The game includes a table ( m + 2 ) x n…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Master Mojtaba has downloaded a new game.
The game includes a table ( m + 2 ) x n (m+2)×n, in which a ball is thrown down from a house of the first row and finally to a house of the row ( m + 2 ) (m+2)th is reached.
in each of the 2 lines ( m + 1 ) There is a (m+1)th hole barrier. Line perforated barrier i I can be divided by 3 numbers A i , B i , c i A i , B i , C i showed ( A i ≤ c i ≤ B i A i ≤C i ≤B i ), which means that this barrier from the house ( i , A i ) (i, A i ) to the house ( i , B i ) (i, B i ) and at home ( i , c i ) (i, C i ) has a hole in it. If the ball hits this obstacle from above, it bounces and leaves the holed house and continues its downward path.
To place the barrier i Iam, the player must d i d i to pay The goal of the game is to be able to place the obstacles with the least cost so that the ball starts from each of the houses of the first row and reaches the same house of the last row (for example, the ball starts from anywhere and reaches the second house of the last row).
The master, who is not bound by holes and empty squares, wants you to play the game for him.
input In the first line, two numbers in order m m and n n have come in line i iam from m m next line of input, 4 numbers A i + 1 A i+1 , B i + 1 B i+1 , c i + 1 c i+1 and d i + 1 d i+1 have come
1 ≤ m ≤ 100
000 1≤m≤100 000 1 ≤ n ≤ 1
000
000
000 1≤n≤1 000 000 000 1 ≤ A i + 1 ≤ c i + 1 ≤ B i + 1 ≤ n 1≤A i+1 ≤C i+1 ≤B i+1 ≤n 1 ≤ d i + 1 ≤ 1
000
000
000 1≤D i+1 ≤1 000 000 000
output If the work requested in the question is not possible, the number
1 −1, and otherwise print the lowest cost.
Sub-issues Constraint score subproblem 111 m ≤ 10 , n ≤ 1
000 m≤10, n≤1000 2 18 m ≤ 200 m ≤ 200 3 22 m ≤ 1
000 m≤1 000 4 49 without additional restrictions Example Sample entry 1 5 6 2 4 3 5 1 2 2 8 3 6 5 2 4 6 4 7 2 4 3 10 Plain text Sample output 1 25 Plain text
If we use the obstacles of the third, fifth and sixth rows, the ball will reach the third house from the last row, starting from each house of the first row.
- Assistant