#K10546. Elevator Button Presses
Elevator Button Presses
Elevator Button Presses
You are given an elevator with a unique set of controls. The elevator has n floors, and the speed (or the number of button presses needed) for ascending each floor is given in an array of integers.
More specifically, you are given an integer n denoting the number of floors in the building, an array speeds of length n where speeds[i]
denotes the number of button presses required to move from floor i+1
to floor i+2
. You are also provided two integers s and t, representing the starting floor and target floor respectively. Your task is to compute the minimum total number of button presses needed to move from floor s to floor t (assuming s < t).
The computation is done simply by summing the speeds from floor s to floor t-1:
It is guaranteed that s is strictly less than t and that the inputs provided will follow these conditions.
inputFormat
The first line contains a single integer n representing the number of floors.
The second line contains n space-separated integers, where the i-th integer represents the speed (i.e., number of button presses) required to move from floor i
to floor i+1
.
The third line contains two space-separated integers: s (the starting floor) and t (the target floor), with s < t.
outputFormat
Output a single integer representing the total number of button presses required to move from floor s to floor t.
## sample5
1 2 3 2 1
1 3
3