Distributed C candies among N boys such that difference between maximum and minimum candies received is K | C # program for the above approach ; 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
using System ; class GFG { static void max_min ( int N , int C , int K ) { int maximum , minimum ; if ( N == 1 ) { maximum = minimum = C ; } else if ( K >= C ) { maximum = C ; minimum = 0 ; } else { maximum = K ; minimum = 0 ; int remain_candy = C - K ; maximum += remain_candy / N ; minimum = remain_candy / N ; if ( remain_candy % N == N - 1 ) { minimum ++ ; } } Console . WriteLine ( " Maximum ▁ = ▁ " + maximum ) ; Console . WriteLine ( " Minimum ▁ = ▁ " + minimum ) ; } static void Main ( ) { int N = 4 ; int C = 12 ; int K = 3 ; max_min ( N , C , K ) ; } }