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. 解决无法修改日志时间的问题(Local time zone must be set--see zic manual page 2019 )

    故障现象 系统日志时间晚了整整8个小时,比如现在是中午12点,日志时间为凌晨4点 date命令报错(Local time zone must be set--see zic manual page) ...

  2. 搭建Harbor

    搭建Harbor 一.安装准备 二.安装docker-ce 三.安装docker-compose 四.安装harbor 5.1下载安装程序 5.2配置harbor.yml 5.3运行install.s ...

  3. win 10 命令行导出注册表

    命令如下: reg  export  注册表中的key  保存路径 reg export HKLM\Software\MyCo\MyApp AppBkUp.reg 如果需要直接覆盖原来的文件,可以加上 ...

  4. CNN卷积核

    一.卷积操作有两个问题: 1. 图像越来越小: 2. 图像边界信息丢失,即有些图像角落和边界的信息发挥作用较少.因此需要padding. 二.卷积核大小通常为奇数 1.一方面是为了方便same卷积pa ...

  5. SSH框架之Hibernate第三篇

    1.1 多表关系分析和创建. 1.1.1 表关系分析和创建 表数据和表数据之间可以存在的关系? 一对多的关系 客户和联系人 建立关系原则: 在多的一方创建一个字段,这个字段作为外键指向一的一方的主键 ...

  6. C# 利用itextsharp、Spire配合使用为pdf文档每页添加水印

    下载类库: 直接下载 引入类库 功能实现 using iTextSharp.text.pdf; using Spire.Pdf; using Spire.Pdf.Graphics; using Sys ...

  7. Business Model Design 业务模型设计

    Note This section is split into two parts, which describe the use of two different Object-relational ...

  8. netcore3.0使用Session

    首先需要明确一点,netcore使用session不能直接使用,必须引用nuget包并做注册之后才能使用. 例如下面的例子,若未注册session服务会报 HttpContext.Session.Se ...

  9. 配置linux 防火墙,只有固定IP和端口才能能访问完美解决

    //添加开放的端口和固定ip vi  /etc/sysconfig/iptables [root@root220156 /]# echo "unset MAILCHECK"> ...

  10. iOS与JS交互-WKWebView

    iOS移动端应用中,一般都会嵌入网页,在网页中处理的结果需要反馈给iOS让移动端做出相应的处理(例如页面跳转), 1.webview的配置 2.代理方法中拿到事件进行处理 二.JS中的配套出发事件 当 ...