CF1168A.Increasing by Modulo
普及/提高-
通过率:0%
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.
输入格式
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.
输出格式
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.
输入输出样例
输入#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 .