Find the minimum and maximum amount to buy all N candies | Python implementation to find the minimum and maximum amount ; function to find the maximum and the minimum cost required ; Sort the array ; print the minimum cost ; print the maximum cost ; Driver Code ; Function call
from math import ceil NEW_LINE def find ( arr , n , k ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE b = int ( ceil ( n / k ) ) NEW_LINE print ( " minimum ▁ " , sum ( arr [ : b ] ) ) NEW_LINE print ( " maximum ▁ " , sum ( arr [ - b : ] ) ) NEW_LINE DEDENT arr = [ 3 , 2 , 1 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE k = 2 NEW_LINE find ( arr , n , k ) NEW_LINE