Distribute R , B beans such that each packet has at least 1 R and 1 B bean with absolute difference at most D | Java program for the above approach ; Function to check if it is possible to distribute R red and B blue beans in packets such that the difference between the beans in each packet is atmost D ; Check for the condition to distributing beans ; Print the answer ; Distribution is not possible ; Driver Code
import java . io . * ; class GFG { static void checkDistribution ( int R , int B , int D ) { if ( Math . max ( R , B ) <= Math . min ( R , B ) * ( D + 1 ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int R = 1 , B = 1 , D = 0 ; checkDistribution ( R , B , D ) ; } }