#USACOC2214B. Air Cownditioning
Air Cownditioning
Description
Farmer John's cows are very particular about the room temperature in theirbarn. Some cows like the temperature to be on the cooler side, while othersprefer more warmth.
Farmer John's barn contains a sequence of stalls, numbered ,each containing a single cow. The -th cow prefers the temperature of her stallto be , and right now the temperature in her stall is . In order tomake sure every cow is comfortable, Farmer John installs a new air conditioningsystem that is controlled in a somewhat interesting way. He can send commandsto the system telling it to either raise or lower the temperature in aconsecutive series of stalls by 1 unit --- for example "raise the temperaturein stalls by 1 unit". The series of stalls could be as short asjust a single stall.
Please help Farmer John determine the minimum number of commands he needs tosend his new air conditioning system so that every cow's stall is at the idealtemperature for its resident cow.
Input Format
The first line of input contains . The next line contains the non-negative integers , separated by spaces. The final linecontains the non-negative integers .
Output Format
Please write a single integer as output containing the minimum number ofcommands Farmer John needs to use.
5
1 5 3 3 4
1 2 2 2 1
5
1 5 3 3 4
1 2 2 2 1
Scoring
- Test cases 2-5 satisfy .
- Test cases 6-8 satisfy .
- Test cases 9-10 satisfy .
- In test cases 1-6 and 9, temperature values are at most .
- In test cases 7-8 and 10, temperature values are at most .
Problem Credit
Problem credits: Brian Dean