The Toronto Transit Commission is staking their image on being The Faster Way to get around Toronto, with a reputation for speedily getting commuters to their destination.
A particular bus route consisting of
As station manager at station
Two buses have arrived, a regular bus and a Rocket bus. The regular bus will stop at any station on the route as long as a passenger wishes to get off. The Rocket bus will only stop at
You would like to minimize the total amount of time passengers spend riding The Faster Way (lest it be branded The Slower Way) by optimally assigning passengers at station
Scoring
For all cases,
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
Input Specification
The first line of input will contain the integers
The next line of input will contain
The last line of input will contain
Output Specification
The minimum cumulative time taken by commuters to get to their destinations.
Sample Input
3 2 2
1 2
1 2
Sample Output
2
Explanation
Assign the first passenger to the regular bus, and the second to the Rocket bus. The total amount of time they will spend together is
Comments
In the input, the stops on the route go up to N, even though the question specifications said it would only be up to N - 1.