CF1593C.Save More Mice
入门
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are one cat, k mice, and one hole on a coordinate line. The cat is located at the point 0, the hole is located at the point n. All mice are located between the cat and the hole: the i-th mouse is located at the point xi (0<xi<n). At each point, many mice can be located.
In one second, the following happens. First, exactly one mouse moves to the right by 1. If the mouse reaches the hole, it hides (i.e. the mouse will not any more move to any point and will not be eaten by the cat). Then (after that the mouse has finished its move) the cat moves to the right by 1. If at the new cat's position, some mice are located, the cat eats them (they will not be able to move after that). The actions are performed until any mouse hasn't been hidden or isn't eaten.
In other words, the first move is made by a mouse. If the mouse has reached the hole, it's saved. Then the cat makes a move. The cat eats the mice located at the pointed the cat has reached (if the cat has reached the hole, it eats nobody).
Each second, you can select a mouse that will make a move. What is the maximum number of mice that can reach the hole without being eaten?
数轴上有一只猫、k 只老鼠和一个洞。猫位于坐标 0 处,洞位于坐标 n 处。所有老鼠均位于猫与洞之间:第 i 只老鼠位于坐标 xi 处(满足 0<xi<n)。在任一坐标点上,可以有任意多只老鼠。
每一秒内,按以下顺序发生事件:首先,恰好一只老鼠向右移动 1 个单位。若该老鼠到达洞的位置,则它躲入洞中(即此后不再移动,也不会被猫吃掉)。然后(在该老鼠完成移动后),猫向右移动 1 个单位。若猫移动后所处的新位置上有老鼠,则猫将吃掉这些老鼠(这些老鼠此后无法再移动)。上述过程持续进行,直到所有老鼠均已躲入洞中或被吃掉为止。
换言之,每轮动作总是由一只老鼠先开始移动。若该老鼠成功抵达洞,则它得救;随后猫再移动一步。猫会吃掉其移动后所在位置上的所有老鼠(若猫移动至洞的位置,则不会吃掉任何老鼠)。
每一秒,你可以选择哪一只老鼠进行移动。问:最多有多少只老鼠能成功躲入洞中而不被猫吃掉?
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.
Each test case consists of two lines. The first line contains two integers n and k (2≤n≤109, 1≤k≤4⋅105). The second line contains k integers x1,x2,…xk (1≤xi<n) — the initial coordinates of the mice.
It is guaranteed that the sum of all k given in the input doesn't exceed 4⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。接下来是 t 个测试用例。
每个测试用例由两行组成。第一行包含两个整数 n 和 k(2≤n≤109,1≤k≤4⋅105)。第二行包含 k 个整数 x1,x2,…,xk(1≤xi<n)—— 老鼠的初始坐标。
保证输入中所有 k 值的总和不超过 4⋅105。
输出格式
For each test case output on a separate line an integer m (m≥0) — the maximum number of mice that can reach the hole without being eaten.
对于每个测试用例,在单独一行输出一个整数 m(m≥0)—— 即能够到达洞口且不被吃掉的老鼠的最大数量。
输入输出样例
输入#1
3 10 6 8 7 5 4 9 4 2 8 1 1 1 1 1 1 1 1 12 11 1 2 3 4 5 6 7 8 9 10 11
输出#1
3 1 4
输入解题思路,AI测评打分。不知道怎么写?