View Code of Problem 3686

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, x;
		cin >> n >> x;
		int a[100000] = { 0 };
		for (int i = 0;i < n;i++)
			cin >> a[i];
		sort(a, a + n);
		int p = 0, q = n - 1, flag = 0;
		while (p < q) {
			if (a[p] + a[q] == x) {
				flag = 1;
				break;
			}
			else if (a[p] + a[q] > x) {
				q--;
			}
			else if (a[p] + a[q] < x) {
				p++;
			}
		}
		if (flag == 1)	cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Double click to view unformatted code.


Back to problem 3686