View Code of Problem 133

#include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp (int a,int b){
return a<b;
}
int main(){
	int t;
	scanf("%d",&t);
	int i,j;
	
	for(i=0;i<t;i++){
		int n,x;
		scanf("%d %d",&n,&x);
		int arr[n];
		for(j=0;j<n;j++){
			
			scanf("%d",&arr[j]);
		}
		int flag=0;
		sort(arr,arr+n,cmp);
		int l=0;
		int r=n-1;
		while(l<r){
			if(arr[l]+arr[r]>x){
				r--;
			}
			else if(arr[l]+arr[r]<x){
				l++;
			}
			else{
				flag=1;
				break;
			}
		}
		
		if(flag){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
		
		
		
	}
	
	
	
	return 0;
} 

Double click to view unformatted code.


Back to problem 133