Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2019 /finals /cold_storage.md
wjomlex's picture
2019 Problems
e329daf verified
|
raw
history blame
4.49 kB

Fred works the night shift in a refrigerator storage warehouse. It's not very exciting work, but Fred has ways to pass the time when nobody's around. For example, lifting fridges turns out to be an amazing bodybuilding method!

The warehouse consists of N sections in a row, numbered from 1 to N. In each section i, there are initially Fi fridges, all arranged in a single stack. The sections are intended to be separate from one another, and only accessible from the outside. To that end, each pair of adjacent sections are separated by a wall, for a total of N-1 walls. However, these walls don't stretch all the way to the ceiling, and aren't necessarily all of the same height. The wall between sections i and i+1 has a height of Hi fridge-heights (Fred has come to measure everything relative to fridge dimensions). Fred's favourite pastime involves climbing over these walls to get between the warehouse's sections!

Fred will begin by entering the warehouse in some section, carrying in some number of new fridges from the outside (yes, he's become strong enough to carry multiple fridges in his arms at once). When he's currently in a certain section s and is carrying f fridges, he may perform any of the following actions:

  • Pick up a fridge from section s's stack of fridges, if it's non-empty. This decreases the number of fridges in that stack by 1, and increases f by 1.
  • Add a fridge that he's carrying onto section s's stack of fridges, if he's carrying at least one fridge. This decreases f by 1, and increases the number of fridges in that stack by 1.
  • Climb onto section s's stack of fridges and jump over a wall into an adjacent section, if the number of fridges in that stack is at least as large as the height of that wall (in fridge-heights). This decreases or increases s by 1.

Fred's goal is to visit all N sections at least once each. He just needs to decide which section he should initially enter and how many additional fridges he should bring from the outside. He has M such possible starting situations in mind, the _i_th of which involves him beginning in section Xi while carrying Yi fridges. For each hypothetical starting situation, please help Fred determine whether or not he will be able to visit all N sections!

Input

Input begins with an integer T, the number of warehouses Fred works at.
For each warehouse, there is first a line containing the space-separated integers N and M.
Then follows a line with the N space-separated integers F1 through FN.
Then follows a line with the N - 1 space-separated integers H1 through HN-1.
Then, M lines follow, the _i_th of which contains the space-separated integers Xi and Yi.

Output

For the _i_th warehouse, print a line containing "Case #i: " followed by a string of M characters, the _i_th of which is "Y" if Fred can visit all N sections from the _i_th starting situation, or "N" otherwise.

Constraints

1 ≤ T ≤ 90
2 ≤ N ≤ 8,000
1 ≤ M ≤ 8,000
0 ≤ Fi ≤ 100,000
1 ≤ Hi ≤ 100,000
1 ≤ XiN
0 ≤ Yi ≤ 1,000,000,000

The sum of N across all T test cases is no greater than 80,000.
The sum of M across all T test cases is no greater than 80,000.

Explanation of Sample

In the first case, the warehouse is arranged as follows:

If Fred begins in section 1 holding 0 fridges, he can't climb over the wall to visit section 2, whereas if he's holding 1 fridge, he can place it in section 1 and then climb over. On the other hand, if he begins in section 2, he can climb over the wall to visit section 1 using the existing fridge, regardless of whether he's holding any himself.

In the second case, consider the first starting situation, in which Fred begins in section 3 holding 4 fridges:

He could begin by placing 3 of his fridges in section 3, and using them to climb over the wall into section 4 while still holding 1 fridge:

He could then place his remaining fridge in section 4, climb back to section 3, pick up a fridge there, and climb over to section 2 while holding that 1 fridge:

Finally, he could place his final fridge in section 2 and climb over to section 1: