Function to initialize the difference array
static void intializeDiff ( int [ , ] D , int [ , ] A ) { for ( int i = 0 ; i < N ; i ++ ) { D [ i , 0 ] = A [ i , 0 ] ; D [ i , M ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) D [ i , j ] = A [ i , j ] - A [ i , j - 1 ] ; } }