B. Anton and Lines
The teacher gave Anton a large geometry homework, but he didn ' t does it (as usual) as he participated in a regular round on Codeforces. In the task he is given a set of n lines defined by the equations y = ki• x + bi. It was necessary to determine whether there are at least one point of intersection of one of the these lines, that lays strictl Y inside the strip between x1 < x2. In other words, was it true that therewas 1≤ i < j ≤ n and x', y', such that:
- y' = ki * x' + bi, that's, point (x', Y') belongs to the line number I;
- y' = kJ * x' + bJ, that's, point ( x', y') belongs to the line number J;
- x 1 < x' < x2, that's, point (x', y') lies inside the strip bounded b Y x1 < x2.
Can ' t leave Anton in trouble, can you? Write A program that solves the given task.
Input
The first line of the input contains an integer n ( 2≤ n ≤100) -the number of lines in the task given to Anton. The second line contains Integers x 1 and x 2 (-1 000 000≤ x Span class= "Lower-index" >1 < x 2≤1) defining the strip inside which you nee D to find a point of intersection of at least-lines.
The following n lines contain integers ki, bi ( - 1 000 000≤ Ki, bi ≤1)-the descriptions of the lines. It is guaranteed so all lines be pairwise distinct, that's, for any II i ≠ J it is true th At either Ki ≠ kJ, or bi ≠ b J.
Output
Print "Yes" (without quotes), if there is at least one intersection of the distinct lines, located strictly inside the Strip. Otherwise print "No" (without quotes).
Sample Test (s) input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
Note
In the first sample there is intersections located on the border of the strip, but there is no intersections located str Ictly inside it.
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 struct Line6 {7 Long LongSy,ey;8}p[100005];9 Ten BOOLCMP (line a,line B) One { A if(A.sy==b.sy)returna.ey<B.ey; - returna.sy<B.sy; - } the - intMain () - { - intN; + while(SCANF ("%d", &n)! =EOF) - { + intx1,x2; Ascanf"%d%d",&x1,&x2); at for(intI=0; i<n;i++) - { - intk,b; -scanf"%d%d",&k,&b); -P[i].sy= (Long Long) k*x1+b; -P[i].ey= (Long Long) k*x2+b; in } -Sort (p,p+n,cmp); to intk=0; + for(; k<n-1; k++) - if(p[k].sy<p[k+1].sy&&p[k].ey>p[k+1].ey) Break; the if(k==n-1) *Puts"NO"); $ ElsePanax NotoginsengPuts"YES"); - } the return 0; +}
Codeforces 593B Anton and Lines