Bingo!
Time limit1sMemory limit128 MB
Given a set of balls, decide whether every value from 0 to N appears as the absolute difference of some ordered pair of balls in the set.
- Level
Easy3 of 10
- Topics
- Brute force, Math, Implementation, Array
- Solved
- No attempts yet
Problem
Albert, Charles and Mary invented a new version of the classic game of Bingo. In traditional Bingo the game is run by a non-player called the caller. At the start each player receives a card holding a unique combination of numbers from to arranged in rows and columns. The caller has a bag containing balls numbered from to . On each turn the caller randomly draws one ball from the bag, announces its number to the players, and sets it aside so it cannot be drawn again. Each player looks for the announced number on the card and marks it if present. The first player to mark a complete pre-announced pattern (for example, a full horizontal line) wins a prize.
In the Albert-Charles-Mary version, on each turn the caller draws a first ball, returns it to the bag, draws a second ball, returns it to the bag, and then calls out the absolute difference between the two ball numbers. To add excitement, before the game starts a possibly empty subset of balls is removed from the bag, leaving at least two balls inside. They want to know whether, using only the balls left in the bag and this new drawing method, every number from to can still be called out.
Input
The input consists of several test cases. Each test case is given on exactly two lines. The first line contains two integers and : is as described above (), and is the number of balls left in the bag (). The second line contains distinct integers , the balls left in the bag ().
The last test case is followed by a line containing two zeros.
Output
For each test case, output a single line containing the uppercase letter Y if every number from to inclusive can be called out, or the uppercase letter N otherwise.