A1190 | [COCI-2010_2011-contest1]#4 TABOVI
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
The first and only line of output must contain the required number, as specified in the problem statement.
输入输出样例
输入 #1
3 3 4 5 6 7 8
输出 #1
3
输入 #2
4 1 2 3 4 3 1 1 0
输出 #2
6
输入 #3
4 5 4 5 5 1 5 0 1
输出 #3
10
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted