CF1168A.Increasing by Modulo
普及+/提高
通过率:0%
时间限制:2.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Toad Zitz has an array of integers, each integer is between 0 and m−1 inclusive. The integers are a1,a2,…,an.
In one operation Zitz can choose an integer k and k indices i1,i2,…,ik such that 1≤i1<i2<…<ik≤n. He should then change aij to ((aij+1)modm) for each chosen integer ij. The integer m is fixed for all operations and indices.
Here xmody denotes the remainder of the division of x by y.
Zitz wants to make his array non-decreasing with the minimum number of such operations. Find this minimum number of operations.
蟾蜍 Zitz 有一个整数数组,其中每个整数均在 0 到 m−1(含端点)之间。这些整数为 a1,a2,…,an。
在一次操作中,Zitz 可以选择一个整数 k 和 k 个下标 i1,i2,…,ik,满足 1≤i1<i2<…<ik≤n。然后,他对每个选定的下标 ij 将 aij 修改为 ((aij+1)modm)。整数 m 在所有操作及下标选择中保持不变。
此处 xmody 表示 x 除以 y 所得的余数。
Zitz 希望以最少的操作次数使该数组变为非递减序列。请找出这个最小操作次数。
输入格式
The first line contains two integers n and m (1≤n,m≤300000) — the number of integers in the array and the parameter m.
The next line contains n space-separated integers a1,a2,…,an (0≤ai<m) — the given array.
第一行包含两个整数 n 和 m(1≤n,m≤300000)—— 分别表示数组中整数的个数和参数 m。
第二行包含 n 个用空格分隔的整数 a1,a2,…,an(0≤ai<m)—— 给定的数组。
输出格式
Output one integer: the minimum number of described operations Zitz needs to make his array non-decreasing. If no operations required, print 0.
It is easy to see that with enough operations Zitz can always make his array non-decreasing.
输出一个整数:Zitz 使其数组变为非递减序列所需的最少操作次数。若无需任何操作,则输出 0。
显然,通过足够多次的操作,Zitz 总能将其数组变为非递减序列。
输入输出样例
输入#1
5 3 0 0 0 1 2
输出#1
0
输入#2
5 7 0 6 1 3 2
输出#2
1
说明/提示
In the first example, the array is already non-decreasing, so the answer is 0.
In the second example, you can choose k=2, i1=2, i2=5, the array becomes [0,0,1,3,3]. It is non-decreasing, so the answer is 1.
在第一个例子中,数组已经是非递减的,因此答案为 0。
在第二个例子中,你可以选择 k=2、i1=2、i2=5,此时数组变为 [0,0,1,3,3]。该数组是非递减的,因此答案为 1。
输入解题思路,AI测评打分。不知道怎么写?