View Code of Problem 133

#include <stdio.h>
#include <string.h>
#include<math.h>
#include<stdlib.h>

int main(){
	
	int t;
	scanf("%d",&t);
	while(t--){
		int n,x;
		scanf("%d%d",&n,&x);
		int s[n];
		for(int i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		int temp,j;
		for(int i=0;i<n;i++){
			temp=s[i];
			for(j=i-1;temp<s[j]&&j>=0;j--){
				s[j+1]=s[j];
			}
			s[j+1]=temp;
		}
		int flag=0;
		int low=0;
		int high=n-1;
		while(low<high){
			if(s[low]+s[high]<x)low++;
			else if(s[low]+s[high]>x)high--;
			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