-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_1048.cpp
More file actions
109 lines (100 loc) · 1.59 KB
/
Copy pathA_1048.cpp
File metadata and controls
109 lines (100 loc) · 1.59 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
solution1:
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100010;
int N[maxn], n, m;
int upper_bound(int l, int r, int x)
{
int left = l, right = r, mid;
while(left < right)
{
mid = (left + right) / 2;
if(N[mid] == x)
return mid;
else if(N[mid] > x)
right = mid - 1;
else
left = mid + 1;
}
return -1;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", &N[i]);
sort(N, N + n);
for(int i = 0; i < n; i++)
{
int j = upper_bound(0, n, m - N[i]);
if(j != -1 && i != j)
{
printf("%d %d", N[i], N[j]);
return 0;
}
}
printf("No Solution");
return 0;
}
*/
/*
solution 2:
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m;
int A[10010];
int main()
{
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", &A[i]);
sort(A, A + n);
int i = 0, j = n - 1;
while(i < j)
{
if(A[i] + A[j] == m)
{
break;
}
else if(A[i] + A[j] < m)
i++;
else
j--;
}
if(i < j)
printf("%d %d", A[i], A[j]);
else
printf("No Solution\n");
return 0;
}
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1005;
int hashtable[N];
int main()
{
int n, m, a;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
{
scanf("%d", &a);
hashtable[a]++;
}
for(int i = 0; i < m; i++)
{
if(hashtable[i] && hashtable[m - i])
{
if(i == m - i && hashtable[i] <= 1)
continue;
printf("%d %d", i, m - i);
return 0;
}
}
printf("No Solution");
return 0;
}