Function to return the amount of wood collected if the cut is made at height m
int woodCollected ( int height [ ] , int n , int m ) { int sum = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( height [ i ] - m <= 0 ) break ; sum += ( height [ i ] - m ) ; } return sum ; }