#include<bits/stdc++.h> using namespace std; //两个数分别从前后往中间判断 int flag判断有无两个数等与x int main() { int t; cin >> t; while (t--) { int a[1000005]; int n,x; cin >>n >> x; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int low = 0, high = n - 1; int flag = 0; while (low < high) { if (a[low] + a[high] == x) { flag = 1; break; } else if (a[low] + a[high] > x) { high--; } else { low++; } } if (flag == 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; } |
Double click to view unformatted code.