HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > SEM 2 - W4 > problem:


2nd-4. 50513 - Climbing Up the Stairs

SEM 2 - W4

Start: Mar.28.2023 at 04:41:52 PM
Finish: Apr.04.2023 at 08:41:52 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (3)

Contest problems

• 50730 - The largest product
• 50731 - The largest product (2)
• 50732 - Sorting
• 2012-11-20. 50792 - The student wi...
• 2nd-4. 50513 - Climbing Up the...

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 Ibrahim Mesecan.

Climbing Up the Stairs

Mr. Shahin Celmeta works as a postman and distributes mails or boxes to the people. He has to go through apartments from different floors of different buildings. All apartment buildings have elevators, but Mr. Celmeta uses the elevator if the next box to deliver is more than two floors above. That is if the next box is just one or two floors above, he uses stairs; otherwise, he uses the elevator.

Question: Read the mail information and show how many floors does he climb.

Input specification
The floor numbers are between 0 and 200. Information for every building is given in a separate line ending with a negative number. And, there are at most 200 integers in every line which are separated by space. The information ends with a negative number at the beginning of line.

Output specification
Show one integer: total number floors he climbs.

Sample Input I
3 6 5 9 6 -1
3 12 5 6 12 14 3 -2
-1
Sample Output I
8

Explanation: There are two buildings. And, there are 5 mails for the first building; and, 7 mails for the second building.

For the second building, when you sort the list, it becomes
  3 3 5 6 12 12 14
The first box has to be delivered to the third floor. Thus, he uses the elevator. After the third floor, he uses the stairs to go to floors five and six. For floor 12, he uses elevator. And then, he uses stairs to climb up the floor 14. As a result, he climbs 5 floors for the second building; and 3 floors for the first building.



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

www.contester.ru