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. subprocess 的 Popen用法

    使用Popen方法时,需要获取输出内容时可以按如下方法获取: # -*- coding:utf-8 -*- import subprocess cmd = r"ping www.baidu. ...

  2. c++ 的namespace及注意事项

    前文 下文中的出现的"当前域"为"当前作用域"的简写 namepsace在c++中是用来避免不同模块下相同名字冲突的一种关键字,本文粗略的介绍了一下namesp ...

  3. 几行代码轻松实现PHP文件打包下载zip

    <?php //获取文件列表 function list_dir($dir){ $result = array(); if (is_dir($dir)){ $file_dir = scandir ...

  4. 新版Notepad++加十六进制查看的插件HexEditor

    Notepad++新版虽然去掉了在线插件商店功能,但是依然可以使用自定义插件 Notepad++下载地址 腾讯(请务必点普通下载):https://pc.qq.com/detail/0/detail_ ...

  5. 关于Oracle数据库的rownum应用

    它是Oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,以此类推,这个伪字段可以用于限制查询返回的总行数,而且rownum不能以任何表的名称作为前缀. 如以下语句将无法 ...

  6. shiro实战(2)--ssm

    一.web.xml的配置 <?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=& ...

  7. react+ant-mobile+lib-flexible构建移动端项目适应设计图尺寸(750)

    使用lib-flexible在react中先安装 npm install lib-flexible --save 因为插件使用的是rem适配,所以安装两个插件 npm install postcss- ...

  8. 【朝花夕拾】Android自定义View篇之(七)Android事件分发机制(下)滑动冲突解决方案总结

    前言 转载请声明,转自[https://www.cnblogs.com/andy-songwei/p/11072989.html],谢谢! 前面两篇文章,花了很大篇幅讲解了Android的事件分发机制 ...

  9. 动态SQL与变量绑定

    有时候动态sql需要进行变量的赋值,这个时候就需要调用系统的存储过程sp_executesql了.使用中还是有些注意事项,代码如下: --字符型字段需声明为NVARCHAR类型 ),) --动态SQL ...

  10. jmap 导出 tomcat 内存快照分析

    登录系统(注意这里启动 tomcat 的用户) # 获取 tomcat 的 pid 号 ps -ef|grep tomcat # 例如这里 pid 号为 13133 jmap -dump:live,f ...