#P5995. Mirror Manufacturing Domination
Mirror Manufacturing Domination
Mirror Manufacturing Domination
Byteasar Corporation outsources the production of wardrobes with mirrors. In a recent tender, ( n ) factories participated. All mirrors are rectangular and cannot be rotated. Each factory ( i ) can produce mirrors whose width lies in the interval ( [w_{min}^{(i)}, w_{max}^{(i)}] ) and height in the interval ( [h_{min}^{(i)}, h_{max}^{(i)}] ).
A factory ( i ) is said to dominate if for every other factory ( j ), every mirror that factory ( j ) can produce, factory ( i ) can also produce. Formally, factory ( i ) dominates factory ( j ) if and only if
[
w_{min}^{(i)} \leq w_{min}^{(j)},\quad w_{max}^{(i)} \geq w_{max}^{(j)}
]
and
[
h_{min}^{(i)} \leq h_{min}^{(j)},\quad h_{max}^{(i)} \geq h_{max}^{(j)}.
]
Byteasar wants to know whether there exists any factory that dominates all the others.
inputFormat
The first line of input contains a single integer ( n ) (( 1 \leq n \leq 10^5 )) representing the number of factories. Each of the following ( n ) lines contains four space-separated integers: ( w_{min} ), ( w_{max} ), ( h_{min} ), and ( h_{max} ) (with ( 1 \leq w_{min} \leq w_{max} \leq 10^9 ) and ( 1 \leq h_{min} \leq h_{max} \leq 10^9 )), describing the mirror production capabilities of a factory.
outputFormat
Output a single line containing either YES
if there exists at least one factory that dominates the production ranges of every other factory, or NO
if no such factory exists.
sample
3
1 5 2 6
2 4 3 5
1 5 1 7
YES