这种两两匹配问题很常见,打比赛的时候想了好久才想起来!,就要特判那个最大的集合,跟其他集合的关系
#include <bits/stdc++.h>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define LLF 0x3f3f3f3f3f3f3f3f
#define f first
#define s second
#define endl '\n'
using namespace std;
const int N = 2e6 + 10, mod = 1e9 + 9;
const int maxn = 500010;
const long double eps = 1e-5;
const int EPS = 500 * 500;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
template<typename T> void read(T &x) {
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
int n, m;
int arr[maxn];
int main() {
//IOS;
int T;
cin >> T;
while(T --) {
cin >> n >> m;
for(int i = 1; i <= m; ++ i) cin >> arr[i];
sort(arr+1,arr+1+m);
if(m == n) {
puts("YES");
continue;
}
int max1 = -1, minnum;
for(int i = 1; i <= m; ++ i)
if(max1 <= arr[i] - arr[i-1] - 1) {
max1 = arr[i] - arr[i-1] - 1;
minnum = arr[i-1] + 1;
}
if(max1 <= n - arr[m]) {
max1 = n - arr[m];
minnum = arr[m] + 1;
}
// cout << max1 << " " << minnum << endl;
if(n - m - max1 >= max1) puts("YES");
else {
int pos = lower_bound(arr+1,arr+1+m,minnum) - arr;
// cout << pos << endl;
if(pos - 1 >= max1 - (n - m - max1)) puts("YES");
else puts("NO");
}
}
}