CF479D.Long Jumps

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ll centimeters. The ruler already has nn marks, with which he can make measurements. We assume that the marks are numbered from 1 to nn 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 ll from the origin. This ruler can be repesented by an increasing sequence a1,a2,...,ana_{1},a_{2},...,a_{n} , where aia_{i} denotes the distance of the ii -th mark from the origin ( a1=0a_{1}=0 , an=la_{n}=l ).

Valery believes that with a ruler he can measure the distance of dd centimeters, if there is a pair of integers ii and jj ( 1<=i<=j<=n1<=i<=j<=n ), such that the distance between the ii -th and the jj -th mark is exactly equal to dd (in other words, ajai=da_{j}-a_{i}=d ).

Under the rules, the girls should be able to jump at least xx centimeters, and the boys should be able to jump at least yy ( x<yx<y ) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances xx and yy .

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 xx and yy . Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.

输入格式

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 ll centimeters. The ruler already has nn marks, with which he can make measurements. We assume that the marks are numbered from 1 to nn 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 ll from the origin. This ruler can be repesented by an increasing sequence a1,a2,...,ana_{1},a_{2},...,a_{n} , where aia_{i} denotes the distance of the ii -th mark from the origin ( a1=0a_{1}=0 , an=la_{n}=l ).

Valery believes that with a ruler he can measure the distance of dd centimeters, if there is a pair of integers ii and jj ( 1<=i<=j<=n1<=i<=j<=n ), such that the distance between the ii -th and the jj -th mark is exactly equal to dd (in other words, ajai=da_{j}-a_{i}=d ).

Under the rules, the girls should be able to jump at least xx centimeters, and the boys should be able to jump at least yy ( x<yx<y ) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances xx and yy .

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 xx and yy . Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.

输出格式

In the first sample it is impossible to initially measure the distance of 230230 centimeters. For that it is enough to add a 2020 centimeter mark or a 230230 centimeter mark.

In the second sample you already can use the ruler to measure the distances of 185185 and 230230 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.

输入输出样例

  • 输入#1

    3 250 185 230
    0 185 250
    

    输出#1

    1
    230
    
  • 输入#2

    4 250 185 230
    0 20 185 250
    

    输出#2

    0
    
  • 输入#3

    2 300 185 230
    0 300
    

    输出#3

    2
    185 230
    

说明/提示

In the first sample it is impossible to initially measure the distance of 230230 centimeters. For that it is enough to add a 2020 centimeter mark or a 230230 centimeter mark.

In the second sample you already can use the ruler to measure the distances of 185185 and 230230 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.

首页