#include<stdio.h> void main() { int t; scanf("%d",&t); while(t--) { int n,x,i,j,temp,low,high,flag=0; scanf("%d %d",&n,&x); int a[n]; for(i=0; i<n; i++) { scanf("%d",&a[i]); } for(i=1; i<n; i++) { temp=a[i]; for(j=i-1; a[j]>temp&&j>=0; j--) { a[j+1]=a[j]; } 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.