A1392 | [COCI-2020-2021-contest5]#3 Po
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Tinky Winky left a sequence of n zeroes in the Tubbytronic Superdome, and left for a walk with Dipsy. When he came back, he saw that a misdeed has been done. The sequence was changed, and Po was smiling mischeviously in the corner of the room.
Oh dear! Po, what have you done?! – asked Tinky Winky in horror.
I enhanced the sequence! – replied Po.
After cross-examination, it was established that Po did a number of enhancements on the sequence. In every enhancement, she took a segment of a sequence and increased all elements in the segment by some positive integer. Also, every two segments were either disjoint or one was completely contained in other.
How many enhancements have you done, Po? – Laa-Laa inquired.
I really don’t know! I’m only sure I did the minimum number of enhancements possible to get this sequence! – said Po exhaustedly.
Then it surely must be m! – proclaimed Noo-Noo. 1 What number did Noo-Noo say?
Oh dear! Po, what have you done?! – asked Tinky Winky in horror.
I enhanced the sequence! – replied Po.
After cross-examination, it was established that Po did a number of enhancements on the sequence. In every enhancement, she took a segment of a sequence and increased all elements in the segment by some positive integer. Also, every two segments were either disjoint or one was completely contained in other.
How many enhancements have you done, Po? – Laa-Laa inquired.
I really don’t know! I’m only sure I did the minimum number of enhancements possible to get this sequence! – said Po exhaustedly.
Then it surely must be m! – proclaimed Noo-Noo. 1 What number did Noo-Noo say?
输入格式
The first line contains an integer n (1 ≤ n ≤ 100 000), the length of the sequence.
The second line contains n nonnegative integers ai (0 ≤ ai ≤ 10^9), the sequence after Po’s enhancements.
The second line contains n nonnegative integers ai (0 ≤ ai ≤ 10^9), the sequence after Po’s enhancements.
输出格式
Output m, the minimum possible number of enhancements.
输入输出样例
输入 #1
3 2 2 2
输出 #1
1
输入 #2
5 2 3 3 3 2
输出 #2
2
In test cases worth 30 points, it holds 1 ≤ n ≤ 1000.
Clarification of the second example:
Po first increased all elements of the sequence by 2, and then increased the middle three by 1.
Clarification of the second example:
Po first increased all elements of the sequence by 2, and then increased the middle three by 1.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted