CF2183C.War Strategy

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A war has broken out! You, as the country's top general, must strategize where to place your troops.

There are nn bases in a line, with the kk-th of which being the home base for your army. Initially, there is only a single soldier at base kk. Each day, the following happens in order:

  • You give out an order by choosing a base ii (1≤i≤n1 \leq i \leq n), and any number of soldiers inside that base (which is allowed to be 00 or all soldiers in that base currently). Then, tell all soldiers you ordered to either move to base i−1i-1 or base i+1i+1. All soldiers must move in the same direction, and no soldier is allowed to move to the left of base 11 or to the right of base nn.
  • Then, a new soldier moves onto base kk. This soldier cannot be ordered by that day's commands.

However, time is tight, and there are only mm days until the enemy attacks. A base is called fortified if at least one soldier resides in it. Your job is to find the maximum number of fortified bases (including the home base) you can have by the end of the mm-th day.

战争爆发了!作为该国的最高统帅,你必须制定部队部署策略。

有 nn 座基地排成一条直线,其中第 kk 座是你的军队的主基地。初始时,仅有 1 名士兵位于第 kk 座基地。每天按如下顺序发生以下事件:

  • 你发布一道命令:选择一座基地 ii(1≤i≤n1 \leq i \leq n),并从中指定任意数量的士兵(可以为 00,也可以是该基地当前全部士兵)。然后,命令所有被选中的士兵全部向左移动至基地 i−1i-1,或全部向右移动至基地 i+1i+1。所有被命令的士兵必须朝同一方向移动,且不允许任何士兵移出基地 11 的左侧或基地 nn 的右侧。
  • 接着,一名新士兵进驻基地 kk。该士兵在当天的命令中不可被选中。

然而时间紧迫,敌军将在 mm 天后发动进攻。若某座基地中至少有一名士兵,则称其为“已设防基地”。你的任务是:求出在第 mm 天结束时,所能达到的最多已设防基地数量(含主基地)。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, mm, kk (1≤k≤n≤1051 \leq k \leq n \leq 10^5, 1≤m≤1091 \leq m \leq 10^9) — denoting the number of bases, the number of days you have to fortify your bases, and the index of the home base.

It is guaranteed that the sum of nn across all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm、kk(1≤k≤n≤1051 \leq k \leq n \leq 10^5,1≤m≤1091 \leq m \leq 10^9),分别表示基地的数量、用于加固基地的天数,以及主基地的索引。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, print the maximum number of bases you can fortify at the end of the mm-th day.

对于每个测试用例,输出在第 mm 天结束时你能加固的基地的最大数量。

输入输出样例

  • 输入#1

    7
    3 1 3
    3 3 2
    4 2 2
    3 2 1
    4 3 3
    7 7 4
    100000 1000000000 100000

    输出#1

    2
    3
    3
    2
    3
    6
    100000

说明/提示

In the second test case, here is one way to fortify 33 bases:

  • On the first day, order 00 soldiers in base 33 to move to base 22. At the end of the day, a new soldier moves to base 22 (there are now 22 soldiers in base 22 and 00 soldiers on any other base).
  • On the second day, order 11 soldier in base 22 to move to base 11. At the end of the day, a new soldier moves to base 22. There are now 22 soldiers in base 22 and 11 soldier on base 11.
  • On the third day, order 22 soldiers in base 22 to move to base 33. At the end of the day, a new soldier moves to base 22. There are now 11 soldier in base 11 and 22, and 22 soldiers in base 33.
  • There is now at least one soldier in each of bases 11, 22, 33. Therefore, the answer is 33.

In the third test case, here is one way you can achieve 33 bases being fortified:

  • On the first day, order the existing soldier to move from base 22 to base 33. At the end of the day, a new soldier moves to base 22.
  • On the second day, order the soldier in base 22 to move to base 11. At the end of the day, a new soldier moves to base 22.
  • There is now a soldier at each of bases 1,2,31,2,3. Therefore, the answer is 33. It can be shown we cannot have more than 33 fortified bases by the end of day 22.

Below is a vivid explanation of the third test case.

在第二个测试用例中,以下是一种加固 33 个基地的方法:

  • 第一天,在基地 33 下达指令,让 00 名士兵移动到基地 22。当天结束时,有 11 名新士兵抵达基地 22(此时基地 22 共有 22 名士兵,其余所有基地的士兵数均为 00)。
  • 第二天,在基地 22 下达指令,让 11 名士兵移动到基地 11。当天结束时,有 11 名新士兵抵达基地 22。此时基地 22 有 22 名士兵,基地 11 有 11 名士兵。
  • 第三天,在基地 22 下达指令,让 22 名士兵移动到基地 33。当天结束时,有 11 名新士兵抵达基地 22。此时基地 11 和基地 22 各有 11 名士兵,基地 33 有 22 名士兵。
  • 此时,基地 11、22、33 中每个基地至少有 11 名士兵。因此,答案为 33。

在第三个测试用例中,以下是一种使 33 个基地被加固的方法:

  • 第一天,指令原有士兵从基地 22 移动到基地 33。当天结束时,有 11 名新士兵抵达基地 22。
  • 第二天,指令基地 22 中的士兵移动到基地 11。当天结束时,有 11 名新士兵抵达基地 22。
  • 此时,基地 11、22、33 各有 11 名士兵。因此,答案为 33。可以证明:到第 22 天结束时,无法使超过 33 个基地被加固。

以下是第三个测试用例的直观图示说明。

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

首页