Step 2 : Do extract minimum k2 k1 1 times and sum all extracted elements . ( This step takes O ( ( K2 k1 ) * Log n ) time )
for i in range ( k1 + 1 , k2 ) : NEW_LINE INDENT ans += a [ 0 ] NEW_LINE a [ 0 ] = a [ n - 1 ] NEW_LINE n -= 1 NEW_LINE minheapify ( a , 0 ) NEW_LINE DEDENT print ( ans ) NEW_LINE