SHARE
TWEET

Untitled

a guest Apr 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. bool BinarySearch(int v[], int st, int dr, int x) {
  6.     int mij;
  7.     if (st > dr) {
  8.         return false;
  9.     } else {
  10.         mij = (st + dr) / 2;
  11.     }
  12.     // conditia de oprire
  13.     if (x == v[mij]) {
  14.         return true;
  15.     }
  16.  
  17.     if (x < v[mij]) {
  18.         BinarySearch(v, mij - 1, dr, x);
  19.     }
  20.  
  21.     if (x > v[mij]) {
  22.         BinarySearch(v, st, mij + 1, x);
  23.     }
  24. }
  25.  
  26. int main() {
  27.     int v[100];
  28.     int n; cin >> n;
  29.     int s; cin >> s;
  30.  
  31.     for (int i = 0; i < n; ++i) {
  32.         cin >> v[i];
  33.     }
  34.  
  35.     // sortez crescator vectorul;
  36.     sort(v, v + n);
  37.    
  38.     for (int i = 0; i < n; ++i) {
  39.         int x = v[i];
  40.         bool p = BinarySearch(v, 0, n - 1, s-x);
  41.  
  42.         if (p) {
  43.             cout << x << " " << s - x;
  44.             break;
  45.         }
  46.     }
  47.     return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top