CF1400E.Clear the Multiset

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 (l≤rl \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 (x≥1x \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?

你有一个多重集合,其中包含若干个整数。初始时,该多重集合包含 a1a_1 个值为 11 的元素、a2a_2 个值为 22 的元素、……、ana_n 个值为 nn 的元素。

你可以执行以下两类操作:

  • 选择两个整数 ll 和 rr(满足 l≤rl \le r),然后从多重集合中各移除一个 ll、一个 l+1l + 1、……、一个 rr;该操作仅在多重集合中每个从 ll 到 rr 的整数至少出现一次时才可执行;
  • 选择两个整数 ii 和 xx(满足 x≥1x \ge 1),然后从多重集合中移除 xx 个值为 ii 的元素;该操作仅在多重集合中值为 ii 的元素至少有 xx 个时才可执行。

问:删除多重集合中所有元素所需的最少操作次数是多少?

输入格式

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

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

第一行包含一个整数 nn(1≤n≤50001 \le n \le 5000)。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(0≤ai≤1090 \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

输入解题思路,AI测评打分。不知道怎么写?

首页