View Code of Problem 133

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

Double click to view unformatted code.


Back to problem 133