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

Сборники > Kovrov IT > задача:


50524 - Elevator

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

Задачи сборника

• 50860 - Number of Student Certificates
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 50531 - File Decryption
• 50525 - Ordering Pizza
• 50451 - Processing Cost
• 50470 - Close Pairs - Revised
• 50752 - Student Groups
• 50524 - Elevator
• 50751 - The biggest Minute
• 50468 - Draw Matrix - 2
• 50998 - CEN112 Homework, quiz av...
• 50804 - Marathon
• 50835 - Club Presidency
• 50526 - Gold Market
• 50872 - Top M Grades
• 50868 - Sort Frequencies

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

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

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

Elevator

The university has a new building. For the economic difficulties, the elevator just carries people from ground floor to the upper floors. Thus people walk down when returning. The people are grouped according to the floor numbers they want to go. Then, until the elevator is full. The elevator climbs up till the last person's destination floor. Then, it returns back to the ground floor. To give a fast service, the elevator starts lifting people who wants to go to the lowest floors.

Question: Write a program that is going to read the people and elevator information, then your program will calculate the total number of floors that the elevator has traveled.

Input specification
You will be given two integers in the first line: the number of floors (n) and the capacity of the elevator (cap: the number of people it can carry at once). Then in the following n lines you will be given integers which are between 0 and 1000. n is an integer between 1 and 30000 and cap is between 1 and 1000.

Output specification
Show one integer: the total number of floors that the elevator has climbed.

Sample Input I
5 6
4
3
8
2
0
Sample Output I
9

Explanation:
There five floors and elevator can carry at most 6 people. And, there are 4 people waiting for the first floor, 3 people waiting for the second floor, etc.

  • On the first run, the elevator takes 4 people for the first floor and 2 people for the second floor. And it leaves them to their floors: climbed up to the second floor.
  • On the second run, it takes 1 person for the second floor and 5 people for the third floor: climbed up to the third floor; and the total number of floors climbed is 5.
  • On the last run, it takes 3 people for the third floor and 2 people for the fourth floor: climbed up to the 4th floor; and the total is 9.


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

www.contester.ru