#197. 计算徒步路径中的大步数

    ID: 197 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatAp-1gesp1循环结构条件结构

计算徒步路径中的大步数

Count Big Steps

Background

Congcong is planning a hiking trip. He has a map recording the altitudes along the trail.

Problem Description

(A variation on the sumHeights problem.) We have an array of heights, representing the altitude along a walking trail. Given start/end indexes into the array, return the number of "big" steps for a walk starting at the startstart index and ending at the endend index. We'll say that step is big if it is 55 or more up or down. The startstart and endend index will both be valid indexes into the array with startendstart \le end.

Input Format

The input consists of a single line.

[h_0 h_1 ... h_{N-1}] start end The first part is a list of integers enclosed in square brackets [] with elements separated by spaces, representing the array of heights. The second part consists of two integers, startstart and endend, representing the starting and ending indices of the walk.

Output Format

Output to standard output in the following format.

count Where count is the number of "big" steps.

Sample

[5 3 6 7 2] 2 4
1
[5 3 6 7 2] 0 1
0
[5 3 6 7 2] 0 4
1

Sample Explanation

For Sample 1: [5 3 6 7 2] 2 4 The start index is 22, and the end index is 44. From heights[2]heights[2] to heights[3]heights[3]: 76=1|7 - 6| = 1, not a big step. From heights[3]heights[3] to heights[4]heights[4]: 27=5|2 - 7| = 5, this is a big step. There is a total of 11 big step.

Constraints

Time limit: 1s, Memory limit: 1024KiB for each test case.