CF1517H.Fly Around the World
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After hearing the story of Dr. Zhang, Wowo decides to plan his own flight around the world.
He already chose n checkpoints in the world map. Due to the landform and the clouds, he cannot fly too high or too low. Formally, let bi be the height of Wowo's aircraft at checkpoint i , xi−≤bi≤xi+ should be satisfied for all integers i between 1 and n , where xi− and xi+ are given integers.
The angle of Wowo's aircraft is also limited. For example, it cannot make a 90 -degree climb. Formally, yi−≤bi−bi−1≤yi+ should be satisfied for all integers i between 2 and n , where yi− and yi+ are given integers.
The final limitation is the speed of angling up or angling down. An aircraft should change its angle slowly for safety concerns. Formally, zi−≤(bi−bi−1)−(bi−1−bi−2)≤zi+ should be satisfied for all integers i between 3 and n , where zi− and zi+ are given integers.
Taking all these into consideration, Wowo finds that the heights at checkpoints are too hard for him to choose. Please help Wowo decide whether there exists a sequence of real numbers b1,…,bn satisfying all the contraints above.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤66666 ). Description of the test cases follows.
The first line of each test case contains a single integer n ( 3≤n≤100000 ).
The i -th of the next n lines contains two integers xi− , xi+ ( −108≤xi−≤xi+≤108 ) denoting the lower and upper bound of bi .
The i -th of the next n−1 lines contains two integers yi+1− , yi+1+ ( −108≤yi+1−≤yi+1+≤108 ) denoting the lower and upper bound of bi+1−bi .
The i -th of the next n−2 lines contains two integers zi+2− , zi+2+ ( −108≤zi+2−≤zi+2+≤108 ) denoting the lower and upper bound of (bi+2−bi+1)−(bi+1−bi) .
It is guaranteed that the sum of n over all test cases does not exceed 200000 .
It is guaranteed that relaxing every constraint by 10−6 (i.e., decrease xi−,yi−,zi− by 10−6 and increase xi+,yi+,zi+ by 10−6 ) will not change the answer.
输出格式
For each test case, output YES if a sequence b1,…,bn satisfying the constraints exists and NO otherwise. The sequence b1,…,bn is not required.
输入输出样例
输入#1
4 3 0 1 0 1 0 1 1 1 1 1 -100 100 3 -967 541 -500 834 -724 669 -858 978 -964 962 -645 705 4 0 0 0 1 0 1 1 1 0 1 0 1 0 1 0 0 0 0 4 0 0 33 34 65 66 100 100 0 100 0 100 0 100 0 0 0 0
输出#1
NO YES YES NO
说明/提示
In the first test case, all bi 's are in [0,1] . Because of the constraints 1=y2−≤b2−b1≤y2+=1 , b2−b1 must be 1 . So b2=1 and b1=0 must hold. Then by 1=y3−≤b3−b2≤y3+=1 , b3 equals 2 . This contradicts the constraint of b3≤1 . So no solution exists.
In the second test case, we can let all bi 's be 0 .
In the third test case, one possible solution is b1=0 , b2=1/3 , b3=2/3 , b4=1 .