Snow Boots
InterviewTime limit2sMemory limit512 MB
For each of B boots with limits on snow depth and step length, decide whether the farmer can walk from tile 1 to tile N, landing only on tiles whose snow is shallow enough.
- Level
Hard8 of 10
- Topics
- Binary search, Sorting, Greedy, Array
- Solved
- No attempts yet
Problem
Winter has arrived at the farm, and with it snow. The path from the farmhouse to the barn is made of tiles, numbered through starting at the house, and tile is covered in feet of snow.
The farmer keeps pairs of boots in the cellar, numbered through . Some pairs are sturdier than others and some are lighter than others. Pair lets the farmer step in snow at most feet deep, and lets him move at most tiles forward in one step.
The farmer starts on tile and has to reach tile to wake the cows. The farmhouse roof covers tile and the barn roof covers tile , so neither tile has snow on it.
One step moves the farmer forward by at least and at most tiles, and the tile he lands on must be covered by at most feet of snow. The snow on the tiles he passes over does not matter. For each pair of boots, decide whether the farmer can get from tile to tile .
Input
The first line contains two space separated integers and ().
The second line contains space separated integers. The th integer is , the depth of the snow on tile (). It is guaranteed that .
Each of the next lines contains two space separated integers. The first integer on line is , the maximum depth of snow that pair can step in. The second integer is , the maximum number of tiles pair can move forward in one step (, ).
Output
Print lines. Line contains if the farmer can walk from tile to tile wearing pair , and otherwise.