310860: CF1901A. Line Trip

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Line Triptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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

Input

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

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.

ExampleInput
3
3 7
1 2 5
3 6
1 2 5
1 10
7
Output
4
3
7
Note

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.

Output

题目大意:
这是一道关于汽车行驶路线的问题。你从数轴上的点0出发,想要到达点x,然后再返回点0。汽车每行驶1单位距离消耗1升汽油。当从点0出发时,汽车油箱是满的。沿途有n个加油站,分别位于点a1, a2, ..., an。到达加油站时,汽车会完全加满油。注意,你只能在加油站加油,且点0和点x没有加油站。需要计算汽车油箱的最小可能容量(以升为单位),以便能够从点0行驶到点x,然后返回点0。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1 ≤ t ≤ 1000),表示测试用例的数量。
- 每个测试用例包含两行:
- 第一行包含两个整数n和x(1 ≤ n ≤ 50;2 ≤ x ≤ 100);
- 第二行包含n个整数a1, a2, ..., an(0 < a1 < a2 < ... < an < x)。

输出:
- 对于每个测试用例,打印一个整数,表示汽车油箱的最小可能容量,以便能够从点0行驶到点x,然后返回。题目大意: 这是一道关于汽车行驶路线的问题。你从数轴上的点0出发,想要到达点x,然后再返回点0。汽车每行驶1单位距离消耗1升汽油。当从点0出发时,汽车油箱是满的。沿途有n个加油站,分别位于点a1, a2, ..., an。到达加油站时,汽车会完全加满油。注意,你只能在加油站加油,且点0和点x没有加油站。需要计算汽车油箱的最小可能容量(以升为单位),以便能够从点0行驶到点x,然后返回点0。 输入输出数据格式: 输入: - 第一行包含一个整数t(1 ≤ t ≤ 1000),表示测试用例的数量。 - 每个测试用例包含两行: - 第一行包含两个整数n和x(1 ≤ n ≤ 50;2 ≤ x ≤ 100); - 第二行包含n个整数a1, a2, ..., an(0 < a1 < a2 < ... < an < x)。 输出: - 对于每个测试用例,打印一个整数,表示汽车油箱的最小可能容量,以便能够从点0行驶到点x,然后返回。

加入题单

上一题 下一题 算法标签: