-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1048.cpp
54 lines (50 loc) · 1 KB
/
1048.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// 1048.cpp
// 算法
//
// Created by 王怡凡 on 17/3/1.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100010;
int all[maxn],m,n;
int upper_bound(int L, int R, int x) {
int left = L, right = R;
int mid;
while(left<=right) {
mid = (left + right)/2;
if(all[mid]==x) {
return mid;
} else if(all[mid]>x){
right = mid - 1;
} else {
left = mid + 1;
}
}
return -1;
}
int main() {
int i,j=-1;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++) {
scanf("%d",&all[i]);
}
sort(all,all+n);
// for(i=0;i<n;i++) {
// printf("all[i]: %d\n",all[i]);
// }
for(i=0;i<n;i++) {
j = upper_bound(i+1, n-1, m-all[i]);
if(all[j]+all[i] == m) {
break;
}
}
if(j==-1) {
printf("No Solution\n");
return 0;
}
printf("%d %d",all[i],all[j]);
return 0;
}