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
def findArray ( N , P ) : NEW_LINE INDENT ans = ( P * ( P + 1 ) ) // 2 + ( N - P ) ; NEW_LINE arr = [ 0 ] * ( N + 1 ) ; NEW_LINE for i in range ( 1 , P + 1 ) : NEW_LINE INDENT arr [ i ] = i ; NEW_LINE DEDENT for i in range ( P + 1 , N + 1 ) : NEW_LINE INDENT arr [ i ] = 1 ; NEW_LINE DEDENT print ( " The ▁ Minimum ▁ Possible ▁ Sum ▁ is : ▁ " , ans ) ; NEW_LINE print ( " The ▁ Array ▁ Elements ▁ are : ▁ " ) ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT N = 5 ; NEW_LINE P = 3 ; NEW_LINE findArray ( N , P ) ; NEW_LINE