Check if given coins can be used to pay a value of S | Java implementation to check if it is possible to pay a value ; Function to check if it is possible to pay a value ; Loop to add the value of coin A ; Condition to check if it is possible to pay a value of S ; Driver Code
class GFG { static void knowPair ( int a , int b , int n , int s , int m ) { int i = 0 , rem = 0 ; int count_b = 0 , flag = 0 ; while ( i <= a ) { rem = s - ( n * i ) ; count_b = rem / m ; if ( rem % m == 0 && count_b <= b ) { flag = 1 ; } i ++ ; } if ( flag == 1 ) { System . out . print ( " YES " + "NEW_LINE"); } else { System . out . print ( " NO " + "NEW_LINE"); } } public static void main ( String [ ] args ) { int A = 1 ; int B = 2 ; int n = 3 ; int S = 4 ; int m = 2 ; knowPair ( A , B , n , S , m ) ; } }