ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Переборные задачи > задача:


50718 - Elevator

Гость
• Вопросы к жюри (1)

Задачи раздела

• 50840 - Tanker trucks
• 50490 - Across the River
• 50828 - Arranging Time Table
• 51067 - Jumping frog
• 51142 - Jump Min Value
• 51082 - Sum is equal to K - 1
• Post Office Delivery
• 50506 - The Biggest Island
• 50718 - Elevator
• 50593 - Transportimi
• 50600 - Выражение
• 50720 - Перестановки (2)

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
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