Choose n elements such that their mean is maximum | Utility function to print the contents of an array ; Function to print the array with maximum mean ; Sort the original array ; Construct new array ; Print the resultant array ; Driver code
< ? php function printArray ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ arr [ $ i ] . " ▁ " ; } function printMaxMean ( $ arr , $ n ) { $ newArr [ $ n ] = array ( ) ; sort ( $ arr , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ newArr [ $ i ] = $ arr [ $ i + $ n ] ; printArray ( $ newArr , $ n ) ; } $ arr = array ( 4 , 8 , 3 , 1 , 3 , 7 , 0 , 4 ) ; $ n = sizeof ( $ arr ) ; printMaxMean ( $ arr , $ n / 2 ) ;