increasing modulo problem

150 Views Asked by At

can someone give me an approach how can i solve this problem? problem link increasing modulo 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.

Edit : I got one approach but he simplified the (aij+1)mod m to difference of two numbers here Please help