[Huawei OD test questions] Take a secret elevator (C++&python) [2023 (B volume) 100 points]

topic content

There is a confidential building, you go from the 0th floor to the designated floor m, you must take the elevator Q according to the following rules: given a sequence of numbers, each time you go up to n floors or down to n floors according to the number n in the sequence, the directions of the two previous operations must be opposite. Solve the sequence combination to reach the floor, if the floor cannot be reached, give the nearest sequence combination smaller than the floor.

illustrate:

There is no limit to the floor range when operating the elevator.
Each item in the sequence must be operated, and only a part cannot be used.

Enter a description:

The first line: the expected floor, the value range [1,50]; the total number of sequences, the value range [1,23] The
second line: sequence, each value range [1,50]

output description

The closest sequence that can reach a floor or be less than that floor

Supplementary Note:

There is no limit to the floor range when operating the elevator.
Each item in the sequence must be operated, and only a part cannot be used

Example 1

enter:

5 3
1 2 6

output:

6

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/131493546