HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50. 50718 - Elevator

Guest
• Review clarifications (1)

Volume problems

• 50564 - Mother's Milk Buckets
• 50593 - Transporter
• 50598 - Minimum Sum
• 50704 - Connected?
• 50705 - Student Clubs
• 50779 - The shortest path in a maze
• 180. 50776 - The number of differen...
• 2007.A. 51071 - Phalanx-2
• 50. 50718 - Elevator
• 50711 - Snail Trails
• 50674 - Collecting Eggs
• 50306 - Beautiful Numbers
• 50411 - Sum of the Leaves
• 50675 - Kruja Boys
• 50421 - Repairing road segments
• 50736 - Top N Donors - 2
• 50775 - Balanced Parenthesis

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ilshat Safiullin.

Elevator

Making an elevator control algorithm is a very complicated task. The main purpose of the elevator control systems is to minimize the total waiting time of the people at the corridor. People don't care about the time passed in the elevator, but they don't have any patience to wait for an elevator.

Question: You should make a program for an N-floor building to let people go to work as quickly as possible. There is only one elevator with the capacity for M people. The elevator travels between two consecutive floors in 1 second and people enter or leave the elevator in 1 second. The elevator is resting on the ground floor (floor 1) at the beginning.

Input specification
There are two integers N (2 ≤ N ≤ 11) and M (M ≤ 30) on the first line of the input. The second line of the input, has N-1 integers pi (pi ≤ M) that represent the number of people in each floor starting from the second floor.

Output specification
The output has a single integer that is the minimum total waiting time.

Sample Input I
4 4
2 0 3
Sample Input II
4 5
2 0 3
Sample Output I
23
Sample Output II
14

Explanation: Elevator goes to the second floor in one second. 2 people there have totally waited 2 seconds. And in one second, they get on to the elevator. Then, elevator goes down to the first floor in one second and people get off from the elevator in one second. Total time passed is 4 seconds.

Then, elevator climbs to the fourth floor in 3 seconds. The people on the fourth floor have waited 7 seconds and it makes 21 seconds totally for all 3 people. This makes totally 23 (21+2) seconds for all the people.



Для отправки решений необходимо выполнить вход.

www.contester.ru