Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- bool BinarySearch(int v[], int st, int dr, int x) {
- int mij;
- if (st > dr) {
- return false;
- } else {
- mij = (st + dr) / 2;
- }
- // conditia de oprire
- if (x == v[mij]) {
- return true;
- }
- if (x < v[mij]) {
- BinarySearch(v, st, mij-1, x);
- }
- if (x > v[mij]) {
- BinarySearch(v, mij + 1, dr, x);
- }
- }
- int main() {
- int v[100];
- int n; cin >> n;
- int s; cin >> s;
- for (int i = 0; i < n; ++i) {
- cin >> v[i];
- }
- // sortez crescator vectorul;
- sort(v, v + n);
- for (int i = 0; i < n; ++i) {
- int x = v[i];
- bool p = BinarySearch(v, 0, n - 1, s-x);
- if (p) {
- cout << x << " " << s - x;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement