CF1400E.Clear the Multiset
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a multiset containing several integers. Initially, it contains a1 elements equal to 1 , a2 elements equal to 2 , ..., an elements equal to n .
You may apply two types of operations:
- choose two integers l and r ( l≤r ), then remove one occurrence of l , one occurrence of l+1 , ..., one occurrence of r from the multiset. This operation can be applied only if each number from l to r occurs at least once in the multiset;
- choose two integers i and x ( x≥1 ), then remove x occurrences of i from the multiset. This operation can be applied only if the multiset contains at least x occurrences of i .
What is the minimum number of operations required to delete all elements from the multiset?
输入格式
The first line contains one integer n ( 1≤n≤5000 ).
The second line contains n integers a1 , a2 , ..., an ( 0≤ai≤109 ).
输出格式
Print one integer — the minimum number of operations required to delete all elements from the multiset.
输入输出样例
输入#1
4 1 4 1 1
输出#1
2
输入#2
5 1 0 1 0 1
输出#2
3