CF1468D.Firecrackers

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Consider a long corridor which can be divided into nn square cells of size 1×11 \times 1. These cells are numbered from 11 to nn from left to right.

There are two people in this corridor, a hooligan and a security guard. Initially, the hooligan is in the aa-th cell, the guard is in the bb-th cell (a≠ba \ne b).

One of the possible situations. The corridor consists of 77 cells, the hooligan is in the 33-rd cell, the guard is in the 66-th (n=7n = 7, a=3a = 3, b=6b = 6).

There are mm firecrackers in the hooligan's pocket, the ii-th firecracker explodes in sis_i seconds after being lit.

The following events happen each second (sequentially, exactly in the following order):

  1. firstly, the hooligan either moves into an adjacent cell (from the cell ii, he can move to the cell (i+1)(i + 1) or to the cell (i−1)(i - 1), and he cannot leave the corridor) or stays in the cell he is currently. If the hooligan doesn't move, he can light one of his firecrackers and drop it. The hooligan can't move into the cell where the guard is;
  2. secondly, some firecrackers that were already dropped may explode. Formally, if the firecracker jj is dropped on the TT-th second, then it will explode on the (T+sj)(T + s_j)-th second (for example, if a firecracker with sj=2s_j = 2 is dropped on the 44-th second, it explodes on the 66-th second);
  3. finally, the guard moves one cell closer to the hooligan. If the guard moves to the cell where the hooligan is, the hooligan is caught.

Obviously, the hooligan will be caught sooner or later, since the corridor is finite. His goal is to see the maximum number of firecrackers explode before he is caught; that is, he will act in order to maximize the number of firecrackers that explodes before he is caught.

Your task is to calculate the number of such firecrackers, if the hooligan acts optimally.

考虑一条长走廊,它可以被划分为 nn 个大小为 1×11 \times 1 的正方形格子。这些格子从左到右编号为 11 到 nn。

走廊中有两个人:一名捣蛋者(hooligan)和一名保安(security guard)。初始时,捣蛋者位于第 aa 个格子,保安位于第 bb 个格子(a≠ba \ne b)。

一种可能的情形。走廊共包含 77 个格子,捣蛋者位于第 33 个格子,保安位于第 66 个格子(n=7n = 7, a=3a = 3, b=6b = 6)。

捣蛋者口袋中有 mm 个鞭炮,其中第 ii 个鞭炮在被点燃后 sis_i 秒爆炸。

每秒内,以下事件按顺序(严格按如下顺序)依次发生:

  1. 首先,捣蛋者可选择移动至一个相邻格子(即从格子 ii 移动到格子 i+1i+1 或 i−1i-1;他不能移出走廊边界),或停留在当前格子。若捣蛋者不移动,则他可以点燃并丢下其中一个鞭炮。捣蛋者不可移动至保安所在的格子;
  2. 其次,部分此前已丢下的鞭炮可能爆炸。形式化地,若鞭炮 jj 在第 TT 秒被丢下,则它将在第 (T+sj)(T + s_j) 秒爆炸(例如,若一个满足 sj=2s_j = 2 的鞭炮在第 44 秒被丢下,则它将在第 66 秒爆炸);
  3. 最后,保安向捣蛋者所在位置靠近一格。若保安移动至捣蛋者所在的格子,则捣蛋者被捕获。

显然,由于走廊长度有限,捣蛋者终将被捕获。他的目标是在被捕获前,使尽可能多的鞭炮成功爆炸;即,他会采取最优策略以最大化被捕获前爆炸的鞭炮数量。

你的任务是:在捣蛋者采取最优策略的前提下,计算被捕获前能够成功爆炸的鞭炮数量。

输入格式

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 four integers nn, mm, aa and bb (2≤n≤1092 \le n \le 10^9; 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5; 1≤a,b≤n1 \le a, b \le n; a≠ba \ne b) — the size of the corridor, the number of firecrackers, the initial location of the hooligan and the initial location of the guard, respectively.

The second line contains mm integers s1s_1, s2s_2, ..., sms_m (1≤si≤1091 \le s_i \le 10^9), where sis_i is the time it takes the ii-th firecracker to explode after it is lit.

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

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

每个测试用例由两行组成。第一行包含四个整数 nn、mm、aa 和 bb(2≤n≤1092 \le n \le 10^9;1≤m≤2⋅1051 \le m \le 2 \cdot 10^5;1≤a,b≤n1 \le a, b \le n;a≠ba \ne b),分别表示走廊的长度、鞭炮的数量、混混的初始位置以及守卫的初始位置。

第二行包含 mm 个整数 s1s_1、s2s_2、...、sms_m(1≤si≤1091 \le s_i \le 10^9),其中 sis_i 表示第 ii 个鞭炮被点燃后到爆炸所需的时间。

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

输出格式

For each test case, print one integer — the maximum number of firecrackers that the hooligan can explode before he is caught.

对于每个测试用例,输出一个整数——即该捣蛋鬼在被抓住之前能够引爆的鞭炮最大数量。

输入输出样例

  • 输入#1

    3
    7 2 3 6
    1 4
    7 2 3 6
    5 1
    7 2 3 6
    4 4

    输出#1

    2
    1
    1

说明/提示

In the first test case, the hooligan should act, for example, as follows:

  • second 1: drop the second firecracker, so it will explode on the 55-th second. The guard moves to the cell 55;
  • second 2: move to the cell 22. The guard moves to the cell 44;
  • second 3: drop the first firecracker, so it will explode on the 44-th second. The guard moves to the cell 33;
  • second 4: move to the cell 11. The first firecracker explodes. The guard moves to the cell 22;
  • second 5: stay in the cell 11. The second firecracker explodes. The guard moves to the cell 11 and catches the hooligan.

在第一个测试用例中,捣蛋鬼应按如下方式行动(例如):

  • 第 1 秒:投下第二枚鞭炮,使其在第 55 秒爆炸。守卫移动至格子 55;
  • 第 2 秒:移动至格子 22。守卫移动至格子 44;
  • 第 3 秒:投下第一枚鞭炮,使其在第 44 秒爆炸。守卫移动至格子 33;
  • 第 4 秒:移动至格子 11。第一枚鞭炮爆炸。守卫移动至格子 22;
  • 第 5 秒:停留在格子 11。第二枚鞭炮爆炸。守卫移动至格子 11 并抓住捣蛋鬼。

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

首页