Distribute R , B beans such that each packet has at least 1 R and 1 B bean with absolute difference at most D | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkDistribution ( int R , int B , int D ) { if ( max ( R , B ) <= min ( R , B ) * ( D + 1 ) ) { cout << " Yes " ; } else { cout << " No " ; } } int main ( ) { int R = 1 , B = 1 , D = 0 ; checkDistribution ( R , B , D ) ; return 0 ; }