Correct Change


Collapse Content

In the Kingdom of Zumbania, the Currency printer can only print the digit 1. Thus they have 3 different denominations: 1, 11, and 111. You need to determine if you can reach a certain sum with a given set of coins.

You will be given a line of input (as an array) consisting of 4 integers for the number of 1-coins, 11-coins, 111-coins, and the desired sum.

For example, the input 1 2 3 356 means there's 1 1-coin, 2 11-coins, 3 111-coins and a desired sum of 356.

Print true if you can select the correct sum from the given coins, and false otherwise.

Sample Cases

  • Given 1 2 3 356 as input, print out true, since the sum of all the coins is 356 (1*1 + 11*2 + 3*111 = 356).
  • Given 2 2 2 269, print out false, since there's no way to reach the given sum.
  • Given 0 11 5 565 print true, since you can take all 11 11-coins and 4 111-coins for a total sum of 565.

Input Details

  • The input starts with N, the number of cases.
  • N cases follow, which each contain the number 4, followed by 4 numbers...
  • ...containing the number of pennies, eleven-coins, 111-coins, and the desired sum

Challenge

Print true if you can get the exact sum and false otherwise.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Comments

Contact Us
Sign in or email us at [email protected]