Dice
InterviewTime limit2sMemory limit1024 MB
Given n dice with f faces and a modifier m, decide whether a reported total S is reachable by checking if S minus m lies between n and n times f.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Khodislav is playing a tabletop role-playing game. He has finally chosen his weapons to deal with a monster and casts the crushing strike. To do this, he rolls dice, adds up the numbers on their faces, and announces the sum to the game master.
A group of identical dice rolls is defined by three integers , , and . Here is the number of dice, is the number of faces on each die, and is the modifier. Each face shows every number from to , any face can come up, and all rolls are independent. For example, if , , and , the player rolls three eight-sided dice, adds the results, and then adds . This is usually written as .
The game master wants to check whether the sum Khodislav reported can actually be obtained from the roll.
Input
The first line contains a single integer (), the number of strikes cast by Khodislav. Each of the following lines describes one strike with four integers: the reported sum , followed by , , and . The constraints are , , , and .
Output
For each strike, in the same order as the input, print YES if the reported sum is achievable, and NO otherwise. Print each answer on its own line.