Statistics

Problem Statement for "Cactus"

Problem Statement

John has a cactus. Sadly, John has only one cactus, and that cactus is lonely. Recently, however, John won $50,000, so he decided to buy some friends for his cactus. Now, everybody knows that the best cactuses in the world can be found at TopCactus.com. TopCactus.com has thousands and thousands of cactuses, and new ones arrive every day. They have so many, that they do not even have time to put prices on all of them. We are not interested in cactuses that do not yet have prices. Now, there are two kinds of priced cactuses. Some of them do not have flowers, and are by themselves gray or green. John does not want any of those. There are also cactuses with flowers. Cactuses with blue flowers are sold for prices ranging from $1,200 to $1,499 inclusive, those with yellow flowers go for between $1,500 and $2,199 inclusive, and those with red flowers cost between $2,200 and $2,999 inclusive. Also, there is a very small number of very, very rare cactuses, which have flowers that are red with a white center. These cactuses cost $3,000 or more and they are so unique and incomparable to each other that no two of them are ever sold for the same price.

Your task is, given the amount of money John spent buying cactuses from TopCactus.com and the number of very rare red-and-white cactuses available at TopCactus, return the number of different combinations of colors of cactuses there are that John could have bought.

For example, if John spent $3,500 and there was at least one very rare cactus: he could have bought one very rare red and white cactus for $3,500; or he could have bought one red cactus and one blue cactus; or two yellow cactuses; or a more expensive yellow and a blue. Return 4.

Definition

Class:
Cactus
Method:
colorCombo
Parameters:
int, int
Returns:
int
Method signature:
int colorCombo(int moneyGone, int numRare)
(be sure your method is public)

Notes

  • Though every cactus is unique and special, and even has its own name, for our purpose of counting color combinations, we consider different cactuses with the same color of flowers to be identical (so a blue cactus for $1,200 and a red cactus for $2,500 is not a different combination from a blue cactus for $1,400 and a red cactus for $2,300).
  • The more expensive a cactus, the more difficult it is to grow or find, of course, so they are less common, but John does not have enough money to exhaust the supply of TopCactus.com of any color of cactus, except the very rare ones with red-and-white flowers, of which TopCactus can have up to five exemplars.
  • We do not know the actual prices of the individual cactuses because they change nearly every week, so we assume that, if John wanted to, he could buy a cactus with a given color of flowers for any price within that range. (In particular, he might blow all $50,000 on a single cactus!)
  • As an exception to that, though, we know that the very rare cactuses with red-and-white flowers have very different personalities (for instance, one of them has a tendency to snap at people) so no two of them are ever the same price.

Constraints

  • moneyGone is between 1200 and 50000 inclusive
  • numRare is between 0 and 5 inclusive

Examples

  1. 3500

    4

    Returns: 4

  2. 6000

    3

    Returns: 18

    Note that John couldn't have bought two very rare red-and-white cactuses as they should be different in price

  3. 50000

    5

    Returns: 21233

  4. 2002

    5

    Returns: 1

  5. 20000

    1

    Returns: 574

  6. 50000

    0

    Returns: 3526

  7. 6001

    3

    Returns: 19

  8. 4500

    5

    Returns: 8

  9. 47000

    0

    Returns: 2949

  10. 50000

    1

    Returns: 8625

  11. 2999

    5

    Returns: 2

  12. 3000

    5

    Returns: 3

  13. 46999

    1

    Returns: 7120

  14. 50000

    2

    Returns: 12825

  15. 1533

    4

    Returns: 1

  16. 49999

    4

    Returns: 18972

  17. 49999

    5

    Returns: 21171

  18. 5999

    3

    Returns: 15

  19. 6099

    5

    Returns: 19

  20. 6100

    5

    Returns: 20

  21. 49983

    0

    Returns: 3493

  22. 49980

    0

    Returns: 3496

  23. 49982

    0

    Returns: 3494

  24. 49981

    0

    Returns: 3495

  25. 49980

    1

    Returns: 8566

  26. 49999

    1

    Returns: 8563

  27. 49982

    1

    Returns: 8564

  28. 49981

    1

    Returns: 8565

  29. 3500

    0

    Returns: 3

    Observe that here, as opposed to in example 0, there are no very rare cactuses at TopCactus.com, so John could not have bought any of them.

  30. 49012

    0

    Returns: 3332

    Ten random test cases

  31. 43512

    1

    Returns: 5694

  32. 11145

    0

    Returns: 55

  33. 12586

    1

    Returns: 146

  34. 22791

    2

    Returns: 1123

  35. 17836

    0

    Returns: 194

  36. 7916

    0

    Returns: 23

  37. 33937

    0

    Returns: 1158

  38. 3411

    3

    Returns: 4

  39. 47137

    4

    Returns: 15752

  40. 49999

    5

    Returns: 21171

  41. 15003

    5

    Returns: 341

  42. 50000

    5

    Returns: 21233

  43. 9002

    5

    Returns: 63

  44. 10201

    5

    Returns: 97


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: