HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Sorting and sequences > problem:


50513 - Climbing Up the Stairs

Guest
• Review clarifications (3)

Section problems

• 50749 - Min Distance
• 50915 - Trip to Korca
• 50802 - Comparing Exams
• 50927 - Health Expenses
• 50745 - Bitonic Sequence
• 50992 - Top K Obese Classes
• 50447 - Swimming Contest - 2
• 50991 - Intersecting Circles
• 50513 - Climbing Up the Stairs
• 50744 - The Smallest Perimeter
• 51002 - The most successful classes
• 50743 - Total Scholarships Discount
• 50847 - The first m trains to leave
• 50984 - Top m hardworking employees
• 50740 - Service Time - 1
• 50750 - Service Time - 2
• 50752 - Student Groups

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