View Code of Problem 133

#include<bits/stdc++.h>
using namespace std;

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,x;
		cin>>n>>x;
		int a[n]={0};
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		int low=0,high=n-1,flag=0;
		while(low<high){
			if(a[low]+a[high]==x){
				flag=1;break;
			}else if(a[low]+a[high]<x){
				low++;
			}else if(a[low]+a[high]>x){
				high--;
			}
		}
		if(flag==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Double click to view unformatted code.


Back to problem 133