CF1901A.Line Trip

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a road, which can be represented as a number line. You are located in the point 00 of the number line, and you want to travel from the point 00 to the point xx, and back to the point 00.

You travel by car, which spends 11 liter of gasoline per 11 unit of distance travelled. When you start at the point 00, your car is fully fueled (its gas tank contains the maximum possible amount of fuel).

There are nn gas stations, located in points a1,a2,…,ana_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 00 and xx.

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 00 to the point xx and back to the point 00.

有一条道路,可以表示为一条数轴。你位于数轴上的点 00,需要从点 00 出发到达点 xx,再返回点 00。

你驾驶一辆汽车,每行驶 11 单位距离消耗 11 升汽油。当你从点 00 出发时,汽车油箱已加满(即装有最大可能的油量)。

共有 nn 个加油站,分别位于点 a1,a2,…,ana_1, a_2, \dots, a_n。当你抵达一个加油站时,你的汽车会被完全加满。注意:你只能在加油站加油,且点 00 和点 xx 处均无加油站。

你需要计算能使你顺利完成从点 00 到点 xx 再返回点 00 的行程所需的汽车油箱最小容积(单位:升)。

输入格式

The first line contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

Each test case consists of two lines:

  • the first line contains two integers nn and xx (1≤n≤501 \le n \le 50; 2≤x≤1002 \le x \le 100);
  • the second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0<a1<a2<⋯<an<x0 \lt a_1 \lt a_2 \lt \dots \lt a_n \lt x).

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示测试用例的数量。

每个测试用例由两行组成:

  • 第一行包含两个整数 nn 和 xx(1≤n≤501 \le n \le 50;2≤x≤1002 \le x \le 100);
  • 第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0<a1<a2<⋯<an<x0 \lt a_1 \lt a_2 \lt \dots \lt a_n \lt 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 00 to the point xx and back.

对于每个测试用例,输出一个整数——使汽车能够从位置 00 行驶到位置 xx 并返回所需的最小油箱容积。

输入输出样例

  • 输入#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 44 liters, you can travel to xx and back as follows:

  • travel to the point 11, then your car's gas tank contains 33 liters of fuel;
  • refuel at the point 11, then your car's gas tank contains 44 liters of fuel;
  • travel to the point 22, then your car's gas tank contains 33 liters of fuel;
  • refuel at the point 22, then your car's gas tank contains 44 liters of fuel;
  • travel to the point 55, then your car's gas tank contains 11 liter of fuel;
  • refuel at the point 55, then your car's gas tank contains 44 liters of fuel;
  • travel to the point 77, then your car's gas tank contains 22 liters of fuel;
  • travel to the point 55, then your car's gas tank contains 00 liters of fuel;
  • refuel at the point 55, then your car's gas tank contains 44 liters of fuel;
  • travel to the point 22, then your car's gas tank contains 11 liter of fuel;
  • refuel at the point 22, then your car's gas tank contains 44 liters of fuel;
  • travel to the point 11, then your car's gas tank contains 33 liters of fuel;
  • refuel at the point 11, then your car's gas tank contains 44 liters of fuel;
  • travel to the point 00, then your car's gas tank contains 33 liters of fuel.

在示例的第一个测试用例中,若汽车的油箱容量为 44 升,则可以按如下方式抵达位置 xx 并返回:

  • 行驶至位置 11,此时汽车油箱剩余 33 升燃油;
  • 在位置 11 加油,此时汽车油箱变为 44 升燃油;
  • 行驶至位置 22,此时汽车油箱剩余 33 升燃油;
  • 在位置 22 加油,此时汽车油箱变为 44 升燃油;
  • 行驶至位置 55,此时汽车油箱剩余 11 升燃油;
  • 在位置 55 加油,此时汽车油箱变为 44 升燃油;
  • 行驶至位置 77,此时汽车油箱剩余 22 升燃油;
  • 行驶至位置 55,此时汽车油箱剩余 00 升燃油;
  • 在位置 55 加油,此时汽车油箱变为 44 升燃油;
  • 行驶至位置 22,此时汽车油箱剩余 11 升燃油;
  • 在位置 22 加油,此时汽车油箱变为 44 升燃油;
  • 行驶至位置 11,此时汽车油箱剩余 33 升燃油;
  • 在位置 11 加油,此时汽车油箱变为 44 升燃油;
  • 行驶至位置 00,此时汽车油箱剩余 33 升燃油。

输入解题思路,AI测评打分。不知道怎么写?

首页