Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has nmarks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where aidenotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
3 250 185 230
0 185 250
1
230
4 250 185 230
0 20 185 250
0
2 300 185 230
0 300
2
185 230
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
求最少要加几个数使得存在a[i]-a[j]=x,a[k]-a[l]=y
毕竟我逗比了……wa了6次之后又被x了
各种无脑二分就过了
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<deque> 9 #include<set> 10 #include<map> 11 #include<ctime> 12 #define LL long long 13 #define inf 0x7ffffff 14 #define pa pair<int,int> 15 #define pi 3.1415926535897932384626433832795028841971 16 using namespace std; 17 LL n,L,x,y; 18 LL a[1000000]; 19 bool xx,yy,xy,yx; 20 LL xxyy,yyxx; 21 inline LL read() 22 { 23 LL x=0,f=1;char ch=getchar(); 24 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 25 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 26 return x*f; 27 } 28 inline bool bsearch(LL x) 29 { 30 int l=1,r=n; 31 while (l<=r) 32 { 33 int mid=(l+r)>>1; 34 if (a[mid]==x)return 1; 35 if (a[mid]<x)l=mid+1; 36 if (a[mid]>x)r=mid-1; 37 } 38 return 0; 39 } 40 int main() 41 { 42 n=read();L=read();x=read();y=read(); 43 for (int i=1;i<=n;i++)a[i]=read(); 44 sort(a+1,a+n+1); 45 for(int i=1;i<=n;i++) 46 { 47 if (bsearch(a[i]+x))xx=1,printf("xx %d ",i); 48 if (bsearch(a[i]+y))yy=1,printf("yy %d ",i); 49 if (bsearch(a[i]+x+y))xy=1,xxyy=a[i]+x; 50 if (bsearch(a[i]+y-x)) 51 { 52 if(a[i]+y<=L) {yyxx=a[i]+y;yx=1;} 53 if(a[i]-x>=0) {yyxx=a[i]-x;yx=1;} 54 } 55 } 56 if (xx&&yy) 57 { 58 printf("0 "); 59 }else 60 if (xx&&!yy) 61 { 62 printf("1 %lld ",y); 63 }else 64 if (yy&&!xx) 65 { 66 printf("1 %lld ",x); 67 }else 68 if (!xx&&!yy&&xy) 69 { 70 printf("1 %lld ",xxyy); 71 }else 72 if (!xx&!yy&&yx) 73 { 74 printf("1 %lld ",yyxx); 75 }else 76 { 77 printf("2 %lld %lld ",x,y); 78 } 79 }