题目描述
Problem Background
Zvonkec is a programmer working at a small company.
Problem Description
Zvonkec has to refactor a source code file every day. What frustrates him the most is the peculiar coding style, especially the uneven indentation, which refers to the number of tab characters (i.e., Tab on the keyboard) at the beginning of each line.
Fortunately, his editor has commands to select a range of consecutive lines and add or remove characters at the beginning of each line. Please help Zvonkec tidy up the code as quickly as possible.
Given the number of lines \( n \), a sequence specifying the current number of tabs at the beginning of each line, and another sequence specifying the desired number of tabs at the beginning of each line.
Zvonkec can execute multiple commands, including:
- Selecting any number of consecutive lines.
- Adding or removing a single tab at the beginning of each selected line.
Regardless of how many lines are selected, the above two actions constitute one command.
It should be noted that it is forbidden to remove more tabs from a line than are actually displayed at the beginning of the line, as the editor will start deleting characters other than tabs.
You are required to calculate the minimum number of commands needed to tidy up the code.
Input Format
The input data consists of three lines.
The first line contains a positive integer \( n \).
The second line contains \( n \) integers \( p_i \), representing the number of tabs at the beginning of the \( i \)-th line before any edits.
The third line contains \( n \) integers \( k_i \), representing the number of tabs Zvonkec wants at the beginning of the \( i \)-th line.
Output Format
The output data consists of one line.
The first line contains a positive integer, representing the required number specified in the problem.
Sample Input and Output
Sample Input #1
3
3 4 5
6 7 8
Sample Output #1
3
Sample Input #2
4
1 2 3 4
3 1 1 0
Sample Output #2
6
Sample Input #3
4
5 4 5 5
1 5 0 1
Sample Output #3
10
Notes
Data Range
- For \( 70\% \) of the data, \( 1 \leq n \leq 100 \), \( 0 \le p_i \le 80 \), \( 0 \leq k_i \leq 80 \).
- For \( 100\% \) of the data, \( 1 \leq n \le 1000 \), \( 0 \le p_i \le 80 \), \( 0 \leq k_i \leq 80 \).
Notes
The problem is translated from COCI2010-2011 CONTEST #1 T5 TABOVI.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分