Submit | All submissions | Best solutions | Back to list |
C1TABOVI - Tabovi |
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
The first line of input contains a positive integer N (N ≤ 1000).
The second line contains a sequence of N integers Pi (0 ≤ Pi ≤ 80), specifying the number of tabs at the start of i-th line before any editing.
The third line contains a sequence of N integers Ki (0 ≤ Ki ≤ 80), specifying the number of tabs that Zvonkec would like at the start of i-th line.
Output
The first and only line of output must contain the required number, as specified in the problem statement.
Example
Input: 3 3 4 5 6 7 8 Output: 3
Input: 4 1 2 3 4 3 1 1 0 Output: 6
Input: 4 5 4 5 5 1 5 0 1 Output: 10
Added by: | Race with time |
Date: | 2010-11-14 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | COCI 2010-2011 1-st Round |
hide comments
2024-11-06 15:51:24
a few testcases: 10 1 4 19 6 32 1 21 25 73 62 65 78 41 43 33 25 44 54 32 25 159 10 60 41 22 12 75 3 7 7 61 22 66 38 71 50 51 1 13 8 45 55 137 10 39 6 41 80 26 51 36 8 60 47 57 47 1 47 51 64 31 13 29 52 152 |
|
2015-07-28 07:46:24 Ankit
nice problem :) |
|
2013-05-22 02:00:06 Ghost Of Perdition
Perfect Problem :) |
|
2012-08-02 21:35:58 _!_pelpendiculal........
@Race with time----can u plzzzz check my solution id 7407681.....it runs well till the 8th case but shows WA after that......plzzzz guide me if there is some tricky test case.....i tried many random cases but it runs well for all the test cases i can think of.....thnx in advance... |