CF1400E.Clear the Multiset
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
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?
你有一个多重集合,其中包含若干个整数。初始时,该多重集合包含 a1 个值为 1 的元素、a2 个值为 2 的元素、……、an 个值为 n 的元素。
你可以执行以下两类操作:
- 选择两个整数 l 和 r(满足 l≤r),然后从多重集合中各移除一个 l、一个 l+1、……、一个 r;该操作仅在多重集合中每个从 l 到 r 的整数至少出现一次时才可执行;
- 选择两个整数 i 和 x(满足 x≥1),然后从多重集合中移除 x 个值为 i 的元素;该操作仅在多重集合中值为 i 的元素至少有 x 个时才可执行。
问:删除多重集合中所有元素所需的最少操作次数是多少?
输入格式
The first line contains one integer n (1≤n≤5000).
The second line contains n integers a1, a2, ..., an (0≤ai≤109).
第一行包含一个整数 n(1≤n≤5000)。
第二行包含 n 个整数 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
输入解题思路,AI测评打分。不知道怎么写?