C. Game of Mathletes

time limit per test

2 seconds

memory limit per test

256 megabytes

Alice and Bob are playing a game. There are n (n is even) integers written on a blackboard, represented by x1,x2,...,xn. There is also a given integer k and an integer score that is initially 0. The game lasts for n2 turns, in which the following events happen sequentially:

  • Alice selects an integer from the blackboard and erases it. Let's call Alice's chosen integer a.
  • Bob selects an integer from the blackboard and erases it. Let's call Bob's chosen integer b.
  • If a+b=k, add 1 to score.

Alice is playing to minimize the score while Bob is playing to maximize the score. Assuming both players use optimal strategies, what is the score after the game ends?

Input

The first line contains an integer t (1≤t≤104) --- the number of test cases.

The first line of each test case contains two integers n and k (2≤n≤2⋅105,1≤k≤2⋅n, n is even).

The second line of each test case contains n integers x1,x2,...,xn (1≤xi≤n) --- the integers on the blackboard.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

Output

For each test case, output the score if both players play optimally.

Example

Input

Copy

复制代码

4

4 4

1 2 3 2

8 15

1 2 3 4 5 6 7 8

6 1

1 1 1 1 1 1

16 9

3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3

Output

Copy

复制代码
2
1
0
4

Note

In the first test case, one way the game may go is as follows:

  • Alice selects 1 and Bob selects 3. The score increases as 1+3=4. Now the two integers remaining on the blackboard are 2 and 2.
  • Alice and Bob both select 2. The score increases as 2+2=4.
  • The game ends as the blackboard now has no integers.

In the third test case, it is impossible for the sum of Alice and Bob's selected integers to be 1, so we answer 0.

Note that this is just an example of how the game may proceed for demonstration purposes. This may not be Alice or Bob's most optimal strategies.

解题说明:此题是一道模拟题,其实就是找出数列中存在多少对数字,其和为K。可以用map来存储数字,求出对数即可。

cpp 复制代码
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, i, j, ans = 0, temp = 0;
		map<int, int>mp;
		cin >> n >> m;
		int a[200005];
		for (i = 0; i < n; i++)
		{
			cin >> a[i];
			if (mp[m - a[i]] != 0)
			{
				ans++;
				mp[m - a[i]]--;
			}
			else
			{
				mp[a[i]]++;
			}
		}
		cout << ans << "\n";
	}
}
相关推荐
吃好睡好便好17 分钟前
MATLAB中图像格式的转换
开发语言·图像处理·学习·计算机视觉·matlab
爱喝水的鱼丶26 分钟前
SAP-ABAP:SELECT大数据量查询性能调优——避免嵌套循环、减少数据库交互的核心方案
开发语言·数据库·sql·性能优化·sap·abap·erp
Dxy123931021629 分钟前
Python 实现POST上行压缩上传可用HTTP库汇总
开发语言·python·http
郝学胜-神的一滴39 分钟前
Python 高级编程 026:序列内核深剖
开发语言·python·程序人生·软件工程
xiaotianyuanma41 分钟前
【计算机毕业设计】基于java web的社区养老服务管理系统设计与实现
java·开发语言·课程设计
Wang's Blog1 小时前
Go-Zero项目开发39: 熔断、限流与降级的高可用实践
开发语言·后端·golang·go-zero
Alan_6911 小时前
第三方API对接的通用封装模式
服务器·开发语言·php
霸道流氓气质1 小时前
Java中集成Weka 技术教程:从入门到工程实践
java·开发语言·数据挖掘
SilentSlot1 小时前
【C/C++】手写 DPDK 协议栈(十二):TCP 并发与自实现 epoll 的就绪事件分发
c语言·c++·tcp/ip