Minimum increment operations to make the array in increasing order | C ++ program to find minimum moves required to make the array in increasing order ; function to find minimum moves required to make the array in increasing order ; to store answer ; iterate over an array ; non - increasing order ; add moves to answer ; increase the element ; return required answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int MinimumMoves ( int a [ ] , int n , int x ) { int ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= a [ i - 1 ] ) { int p = ( a [ i - 1 ] - a [ i ] ) / x + 1 ; ans += p ; a [ i ] += p * x ; } } return ans ; } int main ( ) { int arr [ ] = { 1 , 3 , 3 , 2 } ; int x = 2 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << MinimumMoves ( arr , n , x ) ; return 0 ; }