2023 Huawei OD interview hand-written real questions [minimum time spent in the elevator]

        This question has been found twice online. It is a question in Huawei OD Trusted Subject 2. It is directly used as an interview question. The interview links shared by two classmates who passed the exam during the interview:

#huaweiod interview#_niuke.com

Huawei od interview experience_niuke.com

        They are all the same question, which shows how frequently this question appears ( most people will not be able to write interview questions after the interview. If there are two interview questions with the same question, it means that the probability of passing the exam is very high )

In a company, many people take the elevator every morning, and everyone may go to different floors. At the same time, the elevator has a capacity limit. The elevator can only carry K people at most. It will cost the elevator to go from floor a to floor b. |ab| time.
 Now there are N people, and we know where everyone wants to go. How to take the elevator so that everyone can reach their corresponding floor in the least time. The elevator will finally return to the 1st floor .

 Input
 For each input file, first enter two integers N, K. It means there are N people, and the capacity of the elevator K.
 In the next line, there are N integers, f1, f2, … , fn. Represents the place where everyone wants to arrive.
 (1 <= N, K <= 2000, 1 <= fi <= 2000)

 Output
 the minimum time it takes.

It's a pity that there is no test case, I thought of one myself

おすすめ

転載: blog.csdn.net/misayaaaaa/article/details/133360323