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