#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b; //从小到大 } int main(){ int t,n,x,flag; int i,low,high; scanf("%d",&t); while(t--){ scanf("%d %d",&n,&x); int s[n]; for(i=0;i<n;i++){ scanf("%d",&s[i]); } qsort(s,n,sizeof(s[0]),cmp); flag=0; for(low=0,high=n-1;low<high;){ //调节器 if(s[low]+s[high]==x){ flag=1; break; }else if(s[low]+s[high]<x){ low++; }else{ high--; } } if(flag==1){ printf("YES\n"); }else{ printf("NO\n"); } } return 0; } |
Double click to view unformatted code.