A16300 | Line Trip
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a road, which can be represented as a number line. You are located in the point $0$ of the number line, and you want to travel from the point $0$ to the point $x$ , and back to the point $0$ .
You travel by car, which spends $1$ liter of gasoline per $1$ unit of distance travelled. When you start at the point $0$ , your car is fully fueled (its gas tank contains the maximum possible amount of fuel).
There are $n$ gas stations, located in points $a_1, a_2, \dots, a_n$ . When you arrive at a gas station, you fully refuel your car. Note that you can refuel only at gas stations, and there are no gas stations in points $0$ and $x$ .
You have to calculate the minimum possible volume of the gas tank in your car (in liters) that will allow you to travel from the point $0$ to the point $x$ and back to the point $0$ .
You travel by car, which spends $1$ liter of gasoline per $1$ unit of distance travelled. When you start at the point $0$ , your car is fully fueled (its gas tank contains the maximum possible amount of fuel).
There are $n$ gas stations, located in points $a_1, a_2, \dots, a_n$ . When you arrive at a gas station, you fully refuel your car. Note that you can refuel only at gas stations, and there are no gas stations in points $0$ and $x$ .
You have to calculate the minimum possible volume of the gas tank in your car (in liters) that will allow you to travel from the point $0$ to the point $x$ and back to the point $0$ .
输入格式
The first line contains one integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases.
Each test case consists of two lines:
- the first line contains two integers $n$ and $x$ ( $1 \le n \le 50$ ; $2 \le x \le 100$ );
- the second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 < a_1 < a_2 < \dots < a_n < x$ ).
Each test case consists of two lines:
- the first line contains two integers $n$ and $x$ ( $1 \le n \le 50$ ; $2 \le x \le 100$ );
- the second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 < a_1 < a_2 < \dots < a_n < x$ ).
输出格式
For each test case, print one integer — the minimum possible volume of the gas tank in your car that will allow you to travel from the point $0$ to the point $x$ and back.
输入输出样例
输入 #1
3 3 7 1 2 5 3 6 1 2 5 1 10 7
输出 #1
4 3 7
In the first test case of the example, if the car has a gas tank of $4$ liters, you can travel to $x$ and back as follows:
- travel to the point $1$ , then your car's gas tank contains $3$ liters of fuel;
- refuel at the point $1$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $2$ , then your car's gas tank contains $3$ liters of fuel;
- refuel at the point $2$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $5$ , then your car's gas tank contains $1$ liter of fuel;
- refuel at the point $5$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $7$ , then your car's gas tank contains $2$ liters of fuel;
- travel to the point $5$ , then your car's gas tank contains $0$ liters of fuel;
- refuel at the point $5$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $2$ , then your car's gas tank contains $1$ liter of fuel;
- refuel at the point $2$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $1$ , then your car's gas tank contains $3$ liters of fuel;
- refuel at the point $1$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $0$ , then your car's gas tank contains $3$ liters of fuel.
- travel to the point $1$ , then your car's gas tank contains $3$ liters of fuel;
- refuel at the point $1$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $2$ , then your car's gas tank contains $3$ liters of fuel;
- refuel at the point $2$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $5$ , then your car's gas tank contains $1$ liter of fuel;
- refuel at the point $5$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $7$ , then your car's gas tank contains $2$ liters of fuel;
- travel to the point $5$ , then your car's gas tank contains $0$ liters of fuel;
- refuel at the point $5$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $2$ , then your car's gas tank contains $1$ liter of fuel;
- refuel at the point $2$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $1$ , then your car's gas tank contains $3$ liters of fuel;
- refuel at the point $1$ , then your car's gas tank contains $4$ liters of fuel;
- travel to the point $0$ , then your car's gas tank contains $3$ liters of fuel.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted