CF1895A.Treasure Chest

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Monocarp has found a treasure map. The map represents the treasure location as an OX axis. Monocarp is at 00 , the treasure chest is at xx , the key to the chest is at yy .

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

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

Monocarp can carry the chest, but the chest is pretty heavy. He knows that he can carry it for at most kk 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?

输入格式

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

The only line of each testcase contains three integers x,yx, y and kk ( 1x,y1001 \le x, y \le 100 ; xyx \neq y ; 0k1000 \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.

输出格式

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

输入输出样例

  • 输入#1

    3
    5 7 2
    10 5 0
    5 8 2

    输出#1

    7
    10
    9

说明/提示

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

  • go 55 times to the right ( 55 seconds);
  • pick up the chest ( 00 seconds);
  • go 22 times to the right ( 22 seconds);
  • pick up the key ( 00 seconds);
  • put the chest down ( 00 seconds);
  • open the chest ( 00 seconds).

He only carries the chest for 22 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 33 seconds, while he only has the stamina for 22 seconds. Thus, he carries the chest to 77 , puts it down, moves 11 to the right to pick up the key and returns 11 left to open the chest.

首页