Airplane

Time limit: 1.25s Memory limit: 256MB Input: Output:

While studying for his entrance exam to the National University for Aerospace Magic, Harry Coandă became interested in magical paper airplanes.
Unfortunately, Harry Coandă doesn't have any magic paper at hand so he needs your help with some experiments.

Unfortunately, Harry Coandă doesn’t have any magic paper at hand so he needs your help with some experiments.

Harry designed TT experiments to study the flight path of his airplane. An experiment consists of a room of length NN and height HH that can be represented as an NHN \cdot H grid, and WW wall-like obstacles each with a hole through it. Each wall is placed at distance XiX_i from the left side of the room and has a hole
starting at height SiS_i and going up to height EiE_i. The airplane starts on the far left end of the room at height H2\lfloor \frac{H}{2} \rfloor and needs to reach the far right end of the room without crashing into walls, the floor, or the ceiling.

Unlike a normal paper airplane, Harry’s magical plane doesn’t rely on gravity or air, instead it moves from left to right with a constant horizontal speed of 11 unit per second. Its vertical speed is initially 00 but once every second it can instantly increase or decrease its vertical speed by 11 unit per second. Help Harry by telling him for each experiment whether the plane can take a path to the end of the room without crashing, or if a crash is inevitable

Input data

The first line of the input file contains a single integer TT, the number of test cases. TT test cases follow, each preceded by an empty line.

Each test case consists of:

  • a line containing integers NN, HH, WW: the width of the room, the height of the room, and the number of obstacles respectively.
  • a line containing the WW integers X0,,XW1\mathtt{X}_{0}, \, \ldots, \, \mathtt{X}_{W-1}: the X coordinates of the walls.
  • a line containing the WW integers S0,,SW1\mathtt{S}_{0}, \, \ldots, \, \mathtt{S}_{W-1}: the lower Y coordinates of the holes.
  • a line containing the WW integers E0,,EW1\mathtt{E}_{0}, \, \ldots, \, \mathtt{E}_{W-1}: the upper Y coordinates of the holes.

Output data

The output file must contain TT lines corresponding to the test cases, each consisting of a string: YES if the airplane can reach the end of the room without crashing, or NO otherwise.

Constraints and clarifications

  • 1N1 0001 \le N \le 1 \ 000.
  • 1H1 0001 \le H \le 1 \ 000.
  • 1W5001 \le W \le 500.
  • 1XiN21 \le X_i \le {N-2} for each i=0W1i=0\ldots W-1.
  • 0SiEiH10 \le S_i \le E_i \le {H-1} for each i=0W1i=0\ldots W-1.
  • The sum of NHN \cdot H over the TT testcases does not exceed 1 000 0001 \ 000 \ 000 .

Your program will be tested against several test cases grouped in subtasks.
In order to obtain the score of a subtask, your program needs to correctly solve all of its test cases.

# Points Constraints
1 0 Examples
2 5 H3H \le 3.
3 7 H50,W1H \le 50, W \le 1.
4 13 H50,W2H \le 50, W \le 2
5 19 H50H \le 50.
6 9 W1W \le 1.
7 14 W2W \le 2.
8 33 No additional constraints.

Example

stdin

3
19 10 3
3 9 14
8 0 4
9 1 7
19 15 3
4 7 12
4 13 4
4 14 11
10 16 1
3
0
2

stdout

YES
NO
NO

In the first sample case, it is possible for the airplane to reach the end. One possible path is shown in
the figure. Visited cells are colored in green, with 1,0−1, 0, and +1+1 representing the vertical speed changes

In the \textbf{second sample case} it is impossible for the plane to reach the end without crashing. A path where the plane crashes into the second wall is shown.

In the \textbf{third sample case} it is again impossible to reach the end without crashing. A path where the plane crashes into the floor is shown. Note that plane can hover right above the floor, but if it any moment the height gets below 0 the plane crashes. (Similarly, the plane can crash into the ceiling if the height reaches at least HH).

Log in or sign up to be able to send submissions!