310825: CF1895A. Treasure Chest

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

Description

A. Treasure Chesttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Monocarp has found a treasure map. The map represents the treasure location as an OX axis. Monocarp is at $0$, the treasure chest is at $x$, the key to the chest is at $y$.

Obviously, Monocarp wants to open the chest. He can perform the following actions:

  • go $1$ to the left or $1$ to the right (spending $1$ second);
  • pick the key or the chest up if he is in the same point as that object (spending $0$ seconds);
  • put the chest down in his current point (spending $0$ seconds);
  • open the chest if he's in the same point as the chest and has picked the key up (spending $0$ seconds).

Monocarp can carry the chest, but the chest is pretty heavy. He knows that he can carry it for at most $k$ seconds in total (putting it down and picking it back up doesn't reset his stamina).

What's the smallest time required for Monocarp to open the chest?

Input

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of testcases.

The only line of each testcase contains three integers $x, y$ and $k$ ($1 \le x, y \le 100$; $x \neq y$; $0 \le k \le 100$) — the initial point of the chest, the point where the key is located, and the maximum time Monocarp can carry the chest for.

Output

For each testcase, print a single integer — the smallest time required for Monocarp to open the chest.

ExampleInput
3
5 7 2
10 5 0
5 8 2
Output
7
10
9
Note

In the first testcase, Monocarp can open the chest in $7$ seconds with the following sequence of moves:

  • go $5$ times to the right ($5$ seconds);
  • pick up the chest ($0$ seconds);
  • go $2$ times to the right ($2$ seconds);
  • pick up the key ($0$ seconds);
  • put the chest down ($0$ seconds);
  • open the chest ($0$ seconds).

He only carries the chest for $2$ seconds, which he has the stamina for.

In the second testcase, Monocarp can pick up the key on his way to the chest.

In the third testcase, Monocarp can't use the strategy from the first testcase because he would have to carry the chest for $3$ seconds, while he only has the stamina for $2$ seconds. Thus, he carries the chest to $7$, puts it down, moves $1$ to the right to pick up the key and returns $1$ left to open the chest.

Output

题目大意:
单轮卡普找到了一张藏宝图。该图在OX轴上表示宝藏位置。单轮卡普位于0点,宝箱位于x点,钥匙位于y点。

显然,单轮卡普想要打开宝箱。他可以执行以下操作:
- 向左或向右移动1个单位(花费1秒);
- 如果他与钥匙或宝箱在同一位置,则捡起钥匙或宝箱(不花费时间);
- 在他当前的位置放下宝箱(不花费时间);
- 如果他与宝箱在同一位置并且已经捡起钥匙,则打开宝箱(不花费时间)。

单轮卡普可以携带宝箱,但宝箱非常重。他知道他总共可以携带宝箱最多k秒(放下并再次捡起不会重置他的耐力)。

问:单轮卡普打开宝箱所需的最短时间是多少?

输入数据格式:
第一行包含一个整数t(1≤t≤100)——测试用例的数量。
每个测试用例仅包含一行,包含三个整数x、y和k(1≤x,y≤100;x≠y;0≤k≤100)——宝箱的初始位置、钥匙的位置以及单轮卡普可以携带宝箱的最大时间。

输出数据格式:
对于每个测试用例,打印一个整数——单轮卡普打开宝箱所需的最短时间。题目大意: 单轮卡普找到了一张藏宝图。该图在OX轴上表示宝藏位置。单轮卡普位于0点,宝箱位于x点,钥匙位于y点。 显然,单轮卡普想要打开宝箱。他可以执行以下操作: - 向左或向右移动1个单位(花费1秒); - 如果他与钥匙或宝箱在同一位置,则捡起钥匙或宝箱(不花费时间); - 在他当前的位置放下宝箱(不花费时间); - 如果他与宝箱在同一位置并且已经捡起钥匙,则打开宝箱(不花费时间)。 单轮卡普可以携带宝箱,但宝箱非常重。他知道他总共可以携带宝箱最多k秒(放下并再次捡起不会重置他的耐力)。 问:单轮卡普打开宝箱所需的最短时间是多少? 输入数据格式: 第一行包含一个整数t(1≤t≤100)——测试用例的数量。 每个测试用例仅包含一行,包含三个整数x、y和k(1≤x,y≤100;x≠y;0≤k≤100)——宝箱的初始位置、钥匙的位置以及单轮卡普可以携带宝箱的最大时间。 输出数据格式: 对于每个测试用例,打印一个整数——单轮卡普打开宝箱所需的最短时间。

加入题单

上一题 下一题 算法标签: