-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path42.cpp
More file actions
35 lines (32 loc) · 793 Bytes
/
42.cpp
File metadata and controls
35 lines (32 loc) · 793 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
vector<int> FindNumbersWithSum(vector<int> array, int sum) {
int low = 0, high = array.size() - 1;
vector<int> res;
while (low < high) {
if (array[low] + array[high] == sum) {
res.push_back(array[low]);
res.push_back(array[high]);
return res;
} else if (array[low] + array[high] < sum)
low++;
else high--;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
int sum, n, temp;
vector<int> v;
vector<int> res;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
v.push_back(temp);
}
cin >> sum;
res = FindNumbersWithSum(v, sum);
cout << res[0] << " " << res[1];
return 0;
}