View Code of Problem 133

#include<stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int i,j,flag=0;
		long a[100000],n,x;
		scanf("%ld %ld",&n,&x);
		for(i=0;i<n;i++){
			scanf("%ld",&a[i]);
		}
		for(i=1;i<n;i++){
			if(a[i]<a[i-1]){
				int temp = a[i];
				for(j=i-1;a[j]>temp&&j>=0;j--){
					a[j+1]=a[j];
				}
				a[j+1]=temp;
			}
		}
		i=0;
		j=n-1;
		while(i!=j){
			if(a[i]+a[j]==x){
				printf("YES\n");
				break;
			}else if(a[i]+a[j]>x){
				j--;
			}else if(a[i]+a[j]<x){
				i++;
			}
		}
		if(i==j)
			printf("NO\n");	
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 133