A9767 | Long Jumps
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a_{1},a_{2},...,a_{n}$ , where $a_{i}$ denotes the distance of the $i$ -th mark from the origin ( $a_{1}=0$ , $a_{n}=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, $a_{j}-a_{i}=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.
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 $a_{1},a_{2},...,a_{n}$ , where $a_{i}$ denotes the distance of the $i$ -th mark from the origin ( $a_{1}=0$ , $a_{n}=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, $a_{j}-a_{i}=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.
输入格式
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 $a_{1},a_{2},...,a_{n}$ , where $a_{i}$ denotes the distance of the $i$ -th mark from the origin ( $a_{1}=0$ , $a_{n}=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, $a_{j}-a_{i}=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.
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 $a_{1},a_{2},...,a_{n}$ , where $a_{i}$ denotes the distance of the $i$ -th mark from the origin ( $a_{1}=0$ , $a_{n}=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, $a_{j}-a_{i}=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.
输出格式
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.
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.
输入输出样例
输入 #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 $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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted