#include<iostream> #include<vector> #include<string> #include <algorithm> #include <math.h> using namespace std; int main() { int t; cin >> t; while (t--){ int n,x; cin >> n >> x; int a[n]; for(int i=0; i<n; i++){ cin >> a[i]; } sort(a,a+n); int b = 0; int e = n-1; bool flag = false; while(b<e){ if(a[b]+a[e] == x){ cout << "YES" << endl; flag = true; break; }else if(a[b]+a[e] < x) { b++; }else{ e--; } } if(!flag){ cout << "NO" <<endl; } } return 0; } |
Double click to view unformatted code.