HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Sorting and sequences > problem:


50749 - Min Distance

Guest
• Review clarifications (2)

Section problems

• 50418 - Student averages
• 50875 - Take m-out
• 50748 - Gold Store
• 50766 - Word Puzzle
• 50741 - DNA Distance
• 50934 - Selling Cars
• 50746 - Most Visited
• 50509 - Reading Book
• 50749 - Min Distance
• 50915 - Trip to Korca
• 50802 - Comparing Exams
• 50927 - Health Expenses
• 50745 - Bitonic Sequence
• 50992 - Top K Obese Classes
• 50991 - Intersecting Circles
• 50447 - Swimming Contest - 2
• 50513 - Climbing Up the Stairs

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.

Min Distance

If you have the series 10 7 3 5: The difference between the consecutive numbers is:

  • The difference between 10 and 7 is 3
  • The difference between 7 and 3 is 4
  • The difference between 3 and 5 is 2
Then, the sum of consecutive differences is 9. If you calculate sum of consecutive differences of the same series when they are in this order: 3 7 10 5:
  • The difference between 3 and 7 is 4
  • The difference between 7 and 10 is 3
  • The difference between 10 and 5 is 5
Then, the sum of consecutive differences is 12.

Question: You are asked to read a sequence of numbers and find the sum of consecutive differences such that the result is minimum.

Input specification
You will be given an integer (n) number of numbers where 0 ≤ n ≤ 10,000. Then, in the following n lines you will be given n integers where each number is between -100,000 and +100,000.

Output specification
Show one number: minimum sum of differences between consecutive numbers.

Sample Input I
6
1
5
3
4
7
2
Sample Output I
6



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

www.contester.ru