View Code of Problem 3686

#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; 
int main(){
  	int t;
  	cin>>t;
  	while(t--){
  		int n,x;
  		cin>>n>>x;
  		int num[n];
  		for(int i=0;i<n;i++)
  			cin>>num[i];
		sort(num,num+n);
		int flag=0,low=0,high=n-1;
		while(low<high){
			if(num[low]+num[high]==x){
				cout<<"YES"<<endl;
				flag=1;
				break;
			}
			else if(num[low]+num[high]>x)
				high--;
			else if(num[low]+num[high]<x)
				low++;		
		}//while
		if(flag==0)
			cout<<"NO"<<endl; 		
	  }//while
 
	return 0;
}

Double click to view unformatted code.


Back to problem 3686