CF1400E.Clear the Multiset

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a multiset containing several integers. Initially, it contains a1a_1 elements equal to 11 , a2a_2 elements equal to 22 , ..., ana_n elements equal to nn .

You may apply two types of operations:

  • choose two integers ll and rr ( lrl \le r ), then remove one occurrence of ll , one occurrence of l+1l + 1 , ..., one occurrence of rr from the multiset. This operation can be applied only if each number from ll to rr occurs at least once in the multiset;
  • choose two integers ii and xx ( x1x \ge 1 ), then remove xx occurrences of ii from the multiset. This operation can be applied only if the multiset contains at least xx occurrences of ii .

What is the minimum number of operations required to delete all elements from the multiset?

输入格式

The first line contains one integer nn ( 1n50001 \le n \le 5000 ).

The second line contains nn integers a1a_1 , a2a_2 , ..., ana_n ( 0ai1090 \le a_i \le 10^9 ).

输出格式

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
首页