#P8348. K-Good Sequences in the Shrine

    ID: 21527 Type: Default 1000ms 256MiB

K-Good Sequences in the Shrine

K-Good Sequences in the Shrine

A sequence of positive integers a0, a1, …, an-1 (with n ≥ 2) is called \(k\text{-good}\) if it satisfies the following conditions:

  • Every element is at least \(k\), i.e. \(a_i \ge k\) for all \(0 \le i < n\).
  • For every triple of consecutive elements \(a_{i-1}, a_i, a_{i+1}\) where \(1 \le i \le n-2\), the maximum of the three equals the sum of the other two. In other words, if \(M = \max\{a_{i-1}, a_i, a_{i+1}\}\), then \[ M = (a_{i-1} + a_i + a_{i+1}) - M. \]

You are given \(T\) queries. In each query, you are given five integers \(a_0, a_1, x, y, k\). The task is to determine whether there exists a \(k\text{-good} sequence whose length is at least 2, that starts with the fixed prefix \(a_0, a_1\), and in which some two consecutive terms are exactly \(x\) and \(y\) (in that order).

Note: A sequence of length 2 is trivially valid as long as the two numbers meet the \(\ge k\) condition and match the specified requirements if they form the pair \((x, y)\).

inputFormat

The first line contains an integer \(T\) (the number of queries).

Each of the next \(T\) lines contains five space-separated integers: \(a_0\), \(a_1\), \(x\), \(y\), and \(k\).

All integers are positive and \(k\) is the threshold value for every element in the sequence.

outputFormat

For each query, output a single line containing either YES if there exists a \(k\text{-good}\) sequence satisfying the conditions, or NO otherwise.

sample

5
1 2 3 1 1
2 3 2 3 2
2 4 7 7 3
5 8 8 13 1
3 5 5 2 1
YES

YES NO YES YES

</p>