Codeforces Round #748 (Div. 3) C. Save More Mice

C. Save More Mice

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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?

Input

The first line contains one integer t (1≤t≤1e4) — 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≤1e9, 1≤k≤4⋅1e5). 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⋅1e5.

Output

For each test case output on a separate line an integer mm (m≥0) — the maximum number of mice that can reach the hole without being eaten.

Example

input

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

output

3
1
4

tips:离洞口最近的老鼠是最有可能进洞的,最远的老鼠虽然也能进洞,但那样求不出最多进洞数,按离洞最近的老鼠开始计算,并且当前老鼠的位置必须小于猫所在的位置,这样该老鼠必进洞,否则必被吃

AC代码:

#include <bits/stdc++.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n,k,a[400010];
		cin >> n >> k;
		for(int i = 0;i < k ;i++){
			cin >> a[i];
		}
		sort(a,a+k);
		long long sum = 0;
		long long sum1 = 0;
		int ans = 0;
		for(int i = k - 1;i >= 0;i--){
			if(sum1 >= a[i]){
				break;
			}
			sum += n - a[i];
			sum1 += n -a[i];
			ans++;
		}
		cout << ans << endl; 
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值