View Code of Problem 133

#include<iostream>
#include<string.h>
#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 low=0;
		int heigh=n-1;
		int flag=0;
		while(low<heigh){
			if((a[low]+a[heigh])>x){
				heigh--;
			}else if((a[low]+a[heigh])<x){
				low++;
			}else{
				flag=1;
				break;
			}
		}
		if(flag==1)
		{
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	 
}

Double click to view unformatted code.


Back to problem 133