Generate array with minimum sum which can be deleted in P steps | Function to find the required array ; calculating minimum possible sum ; Array ; place first P natural elements ; Fill rest of the elements with 1 ; Driver Code
< ? php function findArray ( $ N , $ P ) { $ ans = ( $ P * ( $ P + 1 ) ) / 2 + ( $ N - $ P ) ; $ arr [ $ N + 1 ] = array ( ) ; for ( $ i = 1 ; $ i <= $ P ; $ i ++ ) $ arr [ $ i ] = $ i ; for ( $ i = $ P + 1 ; $ i <= $ N ; $ i ++ ) $ arr [ $ i ] = 1 ; echo " The ▁ Minimum ▁ Possible ▁ Sum ▁ is : ▁ " , $ ans , " STRNEWLINE " ; echo " The ▁ Array ▁ Elements ▁ are : ▁ STRNEWLINE " ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) echo $ arr [ $ i ] , ' ▁ ' ; } $ N = 5 ; $ P = 3 ; findArray ( $ N , $ P ) ; ? >