rt,双指针通过记录
双指针code:
#include <bits/stdc++.h>
using namespace std;
int c[1000001];
int main() {
int t, id;
scanf("%d%d", &t, &id);
while (t--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", c + i);
if (id == 4) {
if (n >= 4)
puts("Yes");
else
puts("No");
continue;
}
sort(c + 1, c + n + 1);
int l = 2, r = n - 1, minl = c[1], maxn = c[n];
while (r > l) {
int x = maxn - c[l], y = c[r] - minl;
if (x == y) {
puts("Yes");
goto out;
} else if (x > y)
l++;
else
r--;
}
puts("No");
out:;
}
return 0;
}