#C4205. Valid Student Subsequence

    ID: 47718 Type: Default 1000ms 256MiB

Valid Student Subsequence

Valid Student Subsequence

You are given a list of students. Each student has three integer scores corresponding to three subjects. Your task is to determine whether there exists a subsequence (of at least three students) that satisfies the following conditions:

  • The math scores are strictly increasing.
  • The science scores are non-decreasing.
  • The English scores are non-increasing.

More formally, for a subsequence of three students with scores \( (m_1, s_1, e_1) \), \( (m_2, s_2, e_2) \), and \( (m_3, s_3, e_3) \), it must hold that:

\( m_1 < m_2 < m_3 \), \( s_1 \le s_2 \le s_3 \), and \( e_1 \ge e_2 \ge e_3 \).

If the number of students is less than 3, the answer is NO by default.

inputFormat

The input is read from standard input and has the following format:

T
n1
m11 s11 e11
m12 s12 e12
... 

n2 m21 s21 e21 m22 s22 e22 ...

</p>

Where:

  • T is the number of test cases.
  • For each test case, n denotes the number of students.
  • Each of the following n lines contains three integers representing the scores in three subjects.

outputFormat

For each test case, print a single line to standard output. The line should be YES if there exists a valid subsequence meeting the conditions; otherwise, print NO.

## sample
2
3
70 80 90
60 75 90
80 80 70
5
55 65 75
60 60 70
70 70 65
75 80 80
50 65 85
YES

YES

</p>