View Code of Problem 133

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int a[100002];
int main()
{
    int t;
    scanf("%d",&t);
    int n,x;
    while (t--){
    	scanf("%d%d",&n,&x);
    	for(int i=0;i<n;i++)
    		scanf("%d",&a[i]);
    	sort(a,a+n);
    	int flag=0;
    	int i=0,j=n-1;
    	while(i!=j)
    	{
    		if(a[i]+a[j]==x)
    		{
    			flag=1;
    			break;
			}
			else if(a[i]+a[j]>x)
				j--;
			else i++;
		}
    	if(flag)puts("YES");
    	else puts("NO");
	}
    return 0;
}

Double click to view unformatted code.


Back to problem 133