SHARE
TWEET

Untitled

a guest Jan 24th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int Search_Binary(vector <int> arr, int left, int right, int key)
  8. {
  9.     int midd = 0;
  10.     while (true)
  11.     {
  12.         midd = (left + right) / 2;
  13.  
  14.         if (key < arr[midd])    
  15.             right = midd - 1;    
  16.         else if (key > arr[midd])  
  17.             left = midd + 1;    
  18.         else                      
  19.             return midd;          
  20.  
  21.         if (left > right)          
  22.             return -1;
  23.     }
  24. }
  25.  
  26. int main()
  27. {
  28.     int N;
  29.     cin >> N;
  30.     vector <int> list1(N);    
  31.     for (int i = 0; i < N; i++)
  32.     {
  33.         cin >> list1[i];
  34.     }
  35.     sort(list1.begin(), list1.end());
  36.     int n;
  37.     cin >> n;
  38.     vector <int> list2(n);
  39.     for (int i = 0; i < n; i++)
  40.     {
  41.         cin >> list2[i];
  42.     }
  43.     sort(list2.begin(), list2.end());
  44.     for (int i = 0; i < N; i++)
  45.     {
  46.         int key = 10000 - list1[i];
  47.         if (Search_Binary(list2, 0, n-1, key) != -1) {
  48.             cout << "YES"; return 0;
  49.         }
  50.     }
  51.     cout << "NO";
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