B. Line Segments

Problem Statement

You are given two points (px,py)(p_x, p_y) and (qx,qy)(q_x, q_y) on a Euclidean plane.

You start at the starting point (px,py)(p_x, p_y) and will perform nn operations. In the ii-th operation, you must choose any point such that the Euclidean distance* between your current position and the point is exactly aia_i, and then move to that point.

Determine whether it is possible to reach the terminal point (qx,qy)(q_x, q_y) after performing all operations.

*The Euclidean distance between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is (x1x2)2+(y1y2)2\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t104)(1 \leq t \leq 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n103)(1 \leq n \leq 10^3) — the length of the sequence aa.

The second line of each test case contains four integers px,py,qx,qyp_x, p_y, q_x, q_y (1px,py,qx,qy107)(1 \leq p_x, p_y, q_x, q_y \leq 10^7) — the coordinates of the starting point and terminal point.

The third line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai104)(1 \leq a_i \leq 10^4) — the distance to move in each operation.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output “Yes” if it is possible to reach the terminal point (qx,qy)(q_x, q_y) after all operations; otherwise, output “No”.

You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.

Solution

For each move, we can choose any point on the circle with radius aia_i centered at the current position. The distance to the target point (qx,qy)(q_x, q_y) will then have a range of [max(0,dai),d+ai][\max(0, d - a_i), d + a_i], where dd is the distance from the current position to (qx,qy)(q_x, q_y). We rewrite this range as [dmin,dmax][d_{min}, d_{max}].

  • We begin with the initial range [dmin,dmax][d_{min}, d_{max}], where dmin=dmax=dd_{min} = d_{max} = d, and dd is the distance from (px,py)(p_x, p_y) to (qx,qy)(q_x, q_y).
  • For each move ii, we update the range as follows:
    • dmin=max(0,min(dminai,dmaxai))d'_{min} = \max(0, \min(|d_{min} - a_i|, |d_{max} - a_i|))
    • dmax=dmax+aid'_{max} = d_{max} + a_i
    • If aidmaxa_i \geq d_{max} or aidmina_i \geq d_{min}, then the new minimum distance can be 0, so dmin=0d'_{min} = 0.
    • Update dmin=dmind_{min} = d'_{min} and dmax=dmaxd_{max} = d'_{max} for the next iteration.
  • After all moves, if 00 is within the final range [dmin,dmax][d_{min}, d_{max}], then it’s possible to reach the target point.

submission link