#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) { int T; int n, x; cin >> T; while (T--) { vector<int> v; cin >> n >> x; for (int i = 0; i < n;i++){ int tmp; cin >> tmp; v.push_back(tmp); } sort(v.rbegin(), v.rend()); int index1 = 0, index2 = 0; for (; v[index1] > x && index1 != v.size();index1++){ } int flag = 0; if(index1 != v.size()){ for (; index1 < v.size() - 1;index1++){ for (index2 = index1+1; index2 < v.size();index2++){ if(v[index1] + v[index2] == x) flag = 1; if(flag) break; } if(flag) break; } } if(flag){ cout << "YES" << endl; }else{ cout << "NO" << endl; } } } |
Double click to view unformatted code.