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 n marks, 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 ai denotes 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.

Input

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.

Output

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.

Examples

Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230

Note

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.

OJ-ID:
CodeForces-479D

author:
Caution_X

date of submission:
20191109

tags:
二分,贪心

description modelling:
有一把尺子,尺子上有n个刻度A[i],问能否通过已知的刻度测出长度x和长度y?
输出需要补充的刻度点个数和对应的值

major steps to solve it:
需要补充的刻度点数只能是0,1,2
需要补充的点数为0时可以直接判断
判断能否只补充一个刻度点:①记tx=A[i]+x,表示可以在A[i]右边得出一个刻度能够测出x
再二分查找判断(tx+y)或者(tx-y)在不在已知刻度中,若在,则一个刻度点tx即可,同理,②记ty=A[i]+y,
重复类似①的操作,只要①,②有一个满足条件即可,若都不满足时:记tx=A[i]-x,表示能够在
刻度点A[i]左边找到一个刻度点测出x,记ty=A[i]-y,同理操作。若通过上述操作能够找出,则
只需要补充一个刻度点,否则,需要补充两个刻度点。

warnings:
重点在于点数1和点数2的判断,点数1需要特判
比如x=6,y=7,已知的刻度点有4,5,那么只要补充一个刻度点11即可

AC code:

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn = 1e5+;
int N, L, X, Y, A[maxn]; bool judge (int u) {
if (u < || u > L) return false;
int k = lower_bound(A, A + N, u) - A;
return u == A[k];
} void solve () {
int ans = ;
for (int i = ; i < N; i++) {
if (judge(A[i] - X) || judge(A[i] + X))
ans |= ;
if (judge(A[i] - Y) || judge(A[i] + Y))
ans |= ;
} if (ans == )
printf("0\n");
else if (ans == )
printf("1\n%d\n", X);
else if (ans == )
printf("1\n%d\n", Y);
else { for (int i = ; i < N; i++) {
int tx = A[i] + X;
int ty = A[i] + Y; if (tx <= L && (judge(tx - Y) || judge(tx + Y))) {
printf("1\n%d\n", tx);
return;
} if (ty <= L && (judge(ty - X) || judge(ty + X))) {
printf("1\n%d\n", ty);
return;
}
} for (int i = ; i < N; i++) {
int tx = A[i] - X;
int ty = A[i] - Y; if (tx >= && (judge(tx - Y) || judge(tx + Y))) {
printf("1\n%d\n", tx);
return;
} if (ty >= && (judge(ty - X) || judge(ty + X))) {
printf("1\n%d\n", ty);
return;
}
}
printf("2\n%d %d\n", X, Y);
}
} int main () {
scanf("%d%d%d%d", &N, &L, &X, &Y);
for (int i = ; i < N; i++)
scanf("%d", &A[i]);
solve();
return ;
}

Long Jumps CodeForces - 479D的更多相关文章

  1. Codeforces 479D - Long Jumps

    479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...

  2. 【Codeforces 479D】Long Jumps

    [链接] 我是链接,点我呀:) [题意] 如果存在a[j]-a[i]=d 那么认为可以量出来长度d 现在给你量尺上的n个点. 问你最少要加多少个点,才能够量出来长度x和长度y [题解] 设dic1和d ...

  3. Discrete Centrifugal Jumps CodeForces - 1407D 单调栈+dp

    题意: 给你n个数hi,你刚开始在第1个数的位置,你需要跳到第n个数的位置. 1.对于i.j(i<j) 如果满足 max(hi+1,-,hj−1)<min(hi,hj) max(hi,hj ...

  4. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

  5. codeforces 480B B. Long Jumps(贪心)

    题目链接: B. Long Jumps time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

  7. 【codeforces 791D】 Bear and Tree Jumps

    [题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...

  8. Codeforces 1500F - Cupboards Jumps(set)

    Codeforces 题面传送门 & 洛谷题面传送门 nb tea!!!111 首先很显然的一件事是对于三个数 \(a,b,c\),其最大值与最小值的差就是三个数之间两两绝对值的较大值,即 \ ...

  9. CodeForces 771C Bear and Tree Jumps 树形DP

    题意: 给出一棵树,一个人可以在树上跳,每次最多跳\(k(1 \leq k \leq 5)\)个点 定义\(f(s,t)\)为从顶点\(s\)跳到顶点\(t\)最少需要跳多少次 求\(\sum\lim ...

随机推荐

  1. Samba共享文件

    1 安装samba yum install -y samba* 2 添加用户 useradd smbuser 3 设置共享文件用户的密码 smbpasswd -a smbuser 4 创建公共共享文件 ...

  2. 洛谷 UVA1328 Period

    洛谷 UVA1328 Period 洛谷传送门 题目描述 PDF 输入格式 无 输出格式 无 题意翻译 题意描述 对于给定字符串S的每个前缀,我们想知道它是否为周期串.也就还是说,它是否为某一字符串重 ...

  3. C语言程序设计100例之(21):折半查找

    例21  折半查找 问题描述 顺序查找是一种最简单和最基本的检索方法.其基本思想是:从检索表的一端(如表中第一个记录或最后一个记录)开始,逐个进行记录的关键字和给定值的比较.若某个记录的关键字和给定值 ...

  4. C# -- is和as运算符

    一.is运算符用于判断一个对象是否可以转换为指定的类型,不会抛出异常,返回bool值用来表示是否转换成功: if (myObj is MyClass) { //do... } 当满足以下任意一种情况时 ...

  5. Java分布式系统---消息中间件

    简介 消息中间件也可以称消息队列,是指用高效可靠的消息传递机制进行与平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息队列模型,可以在分布式环境下扩展进程的通信.当下主流 ...

  6. 清新简约风格毕业论文答辩PPT模板推荐

    不管是学生还是老师,应该经常会需要学生答辩的PPT模板,今天给大家推荐织梦58的学生答辩ppt模板. 模版来源:http://ppt.dede58.com/gongzuohuibao/26494.ht ...

  7. SSM框架之SpringMVC(1)入门程序

    SpringMVC(1) 1.三层架构和MVC 1.1. 三层架构 咱们开发服务器端程序,一般都基于两种形式,一种C/S架构程序,一种B/S架构程序 使用Java语言基本上都是开发B/S架构的程序,B ...

  8. Linux-shell学习笔记2

    1.命令的运行顺序 以相对/绝对路径运行命令,例如『 /bin/ls 』或『 ./ls 』: 由 alias 找到该命令来运行: 由 bash 内建的 (builtin) 命令来运行: 通过 $PAT ...

  9. Python遍历字典

    1.遍历key值 1 >>> d = {'Python':'astonishing', 'C++':'complicated', 'Java':'versatile'} 2 > ...

  10. python中函数

    函数特点:一次定义,多次调用 函数阶段:1.定义阶段 2.调用阶段定义阶段的参数叫形参 调用阶段的参数叫实参 例: def test(name,age): print('my name is %s,m ...