Find sum of elements from array1 whose difference with mean is not more than k
$ sumOfElements = 0 ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { $ difference = $ arr1 [ $ i ] - $ mean ; if ( ( $ difference < 0 ) && ( $ k > ( -1 ) * $ difference ) ) { $ sumOfElements += $ arr1 [ $ i ] ; } if ( ( $ difference >= 0 ) && ( $ k > $ difference ) ) { $ sumOfElements += $ arr1 [ $ i ] ; } }