View Code of Problem 3686

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
int num[1000000];

int main()
{
	int t;
	long long n, x;
	cin >> t;
	while(t--)
	{
		int flag = 0;
		cin >> n >> x;
		for(int i = 0; i < n; i++)
			cin >> num[i];
		sort(num, num + n);
		for(int i = n-1; i > 0; i--)
		{
			if(num[i] < x)
			{
				if(i != n-1 && num[i] == num[i+1])
					continue;
				int m = x - num[i];
				for(int j = 0; num[j] <= m && j < i; j++)
					if(num[j] == m)
					{
						flag = 1;
						break;
					 } 
			}
			if(flag)
				break;
		}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3686