COCI '10 Contest 1 #5 Tabovi

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type

Zvonkec is yet another programmer employed in a small company. Every day he has to refactor one file of source code. Much to his dismay, the source is usually far from being clear and tidy. He is especially bothered by uneven indentation, i.e. the number of tabulators (tabs) indenting each line. Fortunately, his editor has a command to select a group of consecutive lines and add or delete a character from the start of each one. Help Zvonkec tidy up the code as quickly as possible.

You are given the number of lines N, a sequence specifying the current number of tabs at the start of each line, and a sequence specifying the required number of tabs at the start of each line.

Zvonkec can execute any number of commands consisting of:

  • selecting any number of consecutive lines
  • adding or deleting a single tab to/from the front of each of the selected lines

The two actions above comprise a single command, regardless of the number of selected lines.

It should be noted that it is forbidden to delete more tabs from a line than are actually present at the start of a line, as the editor would start deleting characters other than tabs.

You are asked to calculate the minimum number of commands required to tidy up the code.

Input Specification

The first line of input contains a positive integer N (N \le 1\,000).

The second line contains a sequence of N integers P_i (0 \le P_i \le 80), specifying the number of tabs at the start of the i-th line before any editing.

The third line contains a sequence of N integers K_i (0 \le K_i \le 80), specifying the number of tabs that Zvonkec would like at the start of the i-th line.

Test cases worth 70\% of total points have N not greater than 100.

Output Specification

The first and only line of output must contain the required number, as specified in the problem statement.

Sample Input 1

3 4 5
6 7 8

Sample Output 1


Sample Input 2

1 2 3 4
3 1 1 0

Sample Output 2


Sample Input 3

5 4 5 5
1 5 0 1

Sample Output 3



There are no comments at the moment.