Problem Statement |
| Nick likes to play the lottery. The cost of a single lottery ticket is price. Nick has exactly four banknotes with values b1, b2, b3 and b4 (some of the values may be equal). He wants to know if it's possible to buy a single lottery ticket without getting any change back. In other words, he wants to pay the exact price of a ticket using any subset of his banknotes. Return "POSSIBLE" if it is possible or "IMPOSSIBLE" if it is not (all quotes for clarity).
|
|
Definition |
| Class: | LotteryTicket | Method: | buy | Parameters: | int, int, int, int, int | Returns: | String | Method signature: | String buy(int price, int b1, int b2, int b3, int b4) | (be sure your method is public) |
|
|
|
|
Constraints |
- | price will be between 1 and 4000, inclusive. |
- | b1, b2, b3 and b4 will each be between 1 and 1000, inclusive. |
|
Examples |
0) | |
| | Returns: "POSSIBLE" | Nick can use the banknote with value b3. |
|
|
1) | |
| | Returns: "POSSIBLE" | Here he can use the banknotes with values b2 and b3. |
|
|
2) | |
| |
3) | |
| | Returns: "POSSIBLE" | All four banknotes must be used. |
|
|
4) | |
| |
5) | |
| | Returns: "POSSIBLE" | Some of the banknote values may be equal. |
|
|
6) | |
| |