Anna is working in an amusement park and she is in charge of building the railroad for a new roller coaster. She has already designed
For each
- when entering the section, there is a speed limit: the speed of the train must be less or equal to
km/h (kilometers per hour), - when leaving the section, the speed of the train is exactly
km/h, regardless of the speed at which the train entered the section.
The finished roller coaster is a single railroad line that contains the
Each meter of the track between two special sections slows the train down by
The final design must satisfy the following requirements:
- the train does not violate any speed limit when entering the special sections;
- the speed of the train is positive at any moment.
In all subtasks except subtask 3, your task is to find the minimum possible total length of tracks between sections. In subtask 3 you only need to check whether there exists a valid roller coaster design, such that each track has zero length.
Implementation details
You should implement the following function (method):
long long plan_roller_coaster(int n, int s[], int t[])
n
: the number of elements ins
andt
(i.e., the number of special sections),s
: array of integers, maximum allowed entry speeds.t
: array of integers, exit speeds.- In all subtasks except subtask 3, the function should return the minimum possible total length of all tracks. In subtask 3 the function should return
if there exists a valid roller coaster design such that each track has zero length, and any positive integer if it does not exist.
Sample
plan_roller_coaster(4, {1, 4, 5, 6}, {7, 3, 8, 6})
In this example there are four special sections. The best solution is to build them in the order
This is how a train travels along this railroad track:
- Initially the speed of the train is
km/h. - The train starts the ride by entering special section
. - The train leaves section
going at km/h. - Then there is a track of length
m. When the train reaches the end of the track, its speed is km/h. - The train enters special section
going at km/h and leaves it at the same speed. - After leaving section
, the train travels along a m long track. Its speed decreases to km/h. - The train enters special section
going at km/h and leaves it going at km/h. - Immediately after special section
the train enters special section . - The train leaves section
. Its final speed is km/h.
The function should return the total length of tracks between the special sections:
Subtasks
In all subtasks
- (11 points):
, - (23 points):
, - (30 points):
. In this subtask your program only needs to check whether the answer is zero or not. If the answer is not zero, any positive integer is considered correct. - (36 points):
.
Comments