Take the Plane
Time limit2sMemory limit1024 MB
Find the cheapest total ticket cost to reach each city from city K, where each single-use ticket covers a rectangle of allowed departure and arrival city ranges.
- Level
Medium7 of 10
- Topics
- Shortest path, Segment tree, Union-find
- Solved
- No attempts yet
Problem
Have you heard of Gyeonggwak, a country where only people good at computer science may live? Gyeonggwak has cities, numbered from 1 to .
The only way to travel between cities in Gyeonggwak is by airplane. For every pair of cities, a flight passes between the two. However, boarding a flight requires an airplane ticket. Gyeonggwak sells tickets, numbered from 1 to . Ticket costs won and can be used only when the departure city number is between and inclusive, and the arrival city number is between and inclusive ().
Each of the tickets is single-use and can be bought only once.
Junjun's house is in city . Right now, Junjun is staying at home.
Let be the minimum total cost of tickets Junjun must buy to travel from his house to city (). Junjun buys all the necessary tickets before leaving home. If no way of buying tickets lets him reach city , define .
Write a program that computes all of .
Input
The first line contains three integers , , and , separated by spaces.
From the second line onward, the next lines describe the tickets. Line contains five integers , , , , and , separated by spaces ().
Output
Print integers on one line, separated by spaces.
Note that .
Constraints
- ()
- ()
- ()