Distribute the white and black objects into maximum groups under certain constraints | Java program for the above approach ; Function to check if it is possible to distribute W and B into maximum groups possible ; If W is greater than B , swap them ; Distribution is not possible ; Distribution is possible ; Driver code ; Input ; Function call
import java . io . * ; class GFG { public static void isPossible ( int W , int B , int D ) { if ( W > B ) { int temp = W ; W = B ; B = temp ; } if ( B > W * ( D + 1 ) ) System . out . println ( " NO " ) ; else System . out . println ( " YES " ) ; } public static void main ( String [ ] args ) { int W = 2 ; int B = 5 ; int D = 2 ; isPossible ( W , B , D ) ; } }