首页 > 其他分享 >Codeforces Round #274 (Div. 2)-D. Long Jumps

Codeforces Round #274 (Div. 2)-D. Long Jumps

时间:2023-06-12 17:37:27浏览次数:41  
标签:return int ruler Jumps Codeforces Long num && s1


原题链接


D. Long Jumps



time limit per test



memory limit per test



input



output


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!

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 ai denotes the distance of the i-th mark from the origin (a1, an = l).

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).

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.

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



nlxy (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.

n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.


Output



v

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


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



#include <bits/stdc++.h>
#define maxn 100005
#define MOD 1000000007
using namespace std;
typedef long long ll;

int n, l, x, y;
int num[maxn];
bool judge(int d){
	int h = lower_bound(num, num+n, d) - num;
	if(num[h] == d)
	 return true;
	return false;
}
int main(){
//	freopen("in.txt", "r", stdin);
	int s1 = 0, s2 = 0;
	scanf("%d%d%d%d", &n, &l, &x, &y);
	for(int i = 0; i < n; i++)
	 scanf("%d", num+i);
	for(int i = 0; i < n; i++){
		if(!s1 && l - x >= num[i] && judge(x+num[i]))
		 s1 = 1;
		if(!s1 && num[i] - x >= 0 && judge(num[i]-x))
		 s1 = 1;
		if(!s2 && l - y >= num[i] && judge(y+num[i]))
		 s2 = 1;
		if(!s2 && num[i] - y >= 0 && judge(num[i]-y))
		 s2 = 1;
		if(s1 && s2)
		 break;
	} 
	if(s1 && s2){
		puts("0");
		return 0;
	}
	if(s1 == 0 && s2 == 1){
		printf("%d\n%d\n", 1, x);
		return 0;
	}
	if(s2 == 0 && s1 == 1){
		printf("%d\n%d\n", 1, y);
		return 0;
	}
	for(int i = 0; i < n; i++){
		if(l - x >= num[i]){
			int d = x + num[i];
			if(l - y >= d && judge(y+d)){
				puts("1");
			    printf("%d\n", d);
				return 0;	
			}
			if(d - y >= 0 && judge(d-y)){
				puts("1");
				printf("%d\n", d);
				return 0;
			}
		}
		if(num[i] - x >= 0){
			int d = num[i] - x;
			if(l - y >= d && judge(y+d)){
				puts("1");
			    printf("%d\n", d);
				return 0;	
			}
			if(d - y >= 0 && judge(d-y)){
				puts("1");
				printf("%d\n", d);
				return 0;
			}
		} 
	}
	puts("2");
	printf("%d %d\n", x, y);
	return 0; 
}




标签:return,int,ruler,Jumps,Codeforces,Long,num,&&,s1
From: https://blog.51cto.com/u_16158872/6464258

相关文章