#include <stdio.h> #include <stdlib.h> #include<ctype.h> #include<string.h> #include<math.h> int main() { int t, n, x,i,j,temp; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &x); int a[n]; for (i = 0; i < n; i++) scanf("%d", &a[i]); for( i=1;i<n;i++) if(a[i]<a[i-1]){ 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; int flag = 0; while (i<j) { if(a[i]+a[j]==x){flag=1;break;} else if(a[i]+a[j]>x){ j--; }else if(a[i]+a[j]<x){ i++; } } if (flag == 1) printf("YES\n"); else printf("NO\n"); } return 0; } |
Double click to view unformatted code.