Distributed C candies among N boys such that difference between maximum and minimum candies received is K | Function to calculate the maximum and minimum number of candies a boy can possess ; All candies will be given to one boy ; All the candies will be given to 1 boy ; Give K candies to 1 st boy initially ; Count remaining candies ; If the last candy of remaining candies is given to the last boy , i . e Nth boy ; Increase minimum count ; Driver code
def max_min ( N , C , K ) : NEW_LINE INDENT maximum = 0 NEW_LINE minimum = 0 NEW_LINE if ( N == 1 ) : NEW_LINE INDENT maximum = minimum = C NEW_LINE DEDENT elif ( K >= C ) : NEW_LINE INDENT maximum = C NEW_LINE minimum = 0 NEW_LINE DEDENT else : NEW_LINE INDENT maximum = K NEW_LINE minimum = 0 NEW_LINE remain_candy = C - K NEW_LINE maximum += remain_candy // N NEW_LINE minimum = remain_candy // N NEW_LINE DEDENT if ( remain_candy % N == N - 1 ) : NEW_LINE INDENT minimum += 1 NEW_LINE DEDENT print ( " Maximum ▁ = ▁ { } " . format ( maximum ) ) NEW_LINE print ( " Minimum ▁ = ▁ { } " . format ( minimum ) ) NEW_LINE DEDENT N = 4 NEW_LINE C = 12 NEW_LINE K = 3 NEW_LINE max_min ( N , C , K ) NEW_LINE