A14613 | Save More Mice
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $x_i$ ( $0 < x_i < 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?
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?
输入格式
The first line contains one integer $t$ ( $1 \le t \le 10^4$ ) — 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 \le n \le 10^9$ , $1 \le k \le 4 \cdot 10^5$ ). The second line contains $k$ integers $x_1, x_2, \dots x_k$ ( $1 \le x_i < n$ ) — the initial coordinates of the mice.
It is guaranteed that the sum of all $k$ given in the input doesn't exceed $4 \cdot 10^5$ .
Each test case consists of two lines. The first line contains two integers $n$ and $k$ ( $2 \le n \le 10^9$ , $1 \le k \le 4 \cdot 10^5$ ). The second line contains $k$ integers $x_1, x_2, \dots x_k$ ( $1 \le x_i < n$ ) — the initial coordinates of the mice.
It is guaranteed that the sum of all $k$ given in the input doesn't exceed $4 \cdot 10^5$ .
输出格式
For each test case output on a separate line an integer $m$ ( $m \ge 0$ ) — the maximum number of mice that can reach the hole without being eaten.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted