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