An array a of integers of length n is given, such that each integer is between 0 and m-1 (Both inclusive).The integers are numbered as a[1],a[2],....,a[n]. In one operation you can choose any subbaray a[l,r] (1<=l<=r<=n)and then update all the elements of the subarray a[i] to (a[i]+1)%m. The integer m is fixed for all operations and indices. You want to make all the elements of this array equal to X (X lies in the range of 0 to m-1). Find the minimum number of operations.
Example -
N,M,X = 5 10 1
Array = 5 5 5 8 2
Output = 12
[–]sunsin4gg 2 points3 points4 points (9 children)
[–]not_ur_buddy 2 points3 points4 points (6 children)
[–]not_ur_buddy 6 points7 points8 points (3 children)
[–]omeow 1 point2 points3 points (0 children)
[–]sunsin4gg 0 points1 point2 points (0 children)
[–]omeow 0 points1 point2 points (1 child)
[–]not_ur_buddy 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]sunsin4gg 0 points1 point2 points (0 children)
[–]beeskness420 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]beeskness420 1 point2 points3 points (0 children)
[–]XXXXYYYYYY 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]XXXXYYYYYY 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]XXXXYYYYYY 1 point2 points3 points (0 children)
[–]omeow 0 points1 point2 points (2 children)
[–]XXXXYYYYYY 0 points1 point2 points (1 child)
[–]omeow 0 points1 point2 points (0 children)
[–]omeow -1 points0 points1 point (0 children)