Interstellar Train
Time limit1sMemory limit1024 MB
Find the minimum total cost of train fares plus waiting-meal charges to travel from planet 0 to planet N-1, where each meal must fall in its time window.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Greedy
- Solved
- No attempts yet
Problem
In the year 2992, robots have taken most jobs. Many people now have plenty of free time, and your family has decided to travel between the stars!
There are reachable planets, numbered from to , and interstellar train routes. Route () leaves planet at time , arrives at planet at time , and costs . Trains are the only way to travel between planets. You can only get off a train at its destination planet, and you must board the next train from that same planet. Transfers take no time. Formally, a sequence of trains is valid if and only if for every , and .
Interstellar travel takes a long time, so meals add a significant cost on top of the train fares. Fortunately, interstellar trains provide unlimited food for free. If you take route , you can eat any number of meals at no cost at any time between and (inclusive). While your family waits for the next train on planet , however, each meal costs .
Your family must eat meals. The -th meal () can be eaten instantaneously at any time between and (inclusive).
At time , your family is on planet . Find the minimum total cost to reach planet . If it is impossible to reach planet , the answer is .
Constraints
- .
- .
- , .
- .
- .
- .