标签:
#include<stdio.h> #include<algorithm> using namespace std; const int maxn=100010; int n,m; int value[maxn]; int binarySearch(int l,int r,int x) { while(l<=r) { int mid=(r+l)/2; if(x==value[mid]) return mid; else if(x>value[mid]) l=mid+1; else r=mid-1; } return -1; } int main() { //freopen("in.txt","r",stdin); scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%d",&value[i]); sort(value,value+n); for(int i=0;i<n;i++) { if(value[i]>=m/2+1) break; int tmp=m-value[i]; int index=binarySearch(i+1,n-1,tmp);//二分查找 if(index!=-1) { printf("%d %d\n",value[i],value[index]); return 0; } } printf("No Solution\n"); return 0; }
标签:
原文地址:http://blog.csdn.net/u014429500/article/details/44115235