SHARE
TWEET

Untitled

a guest Nov 14th, 2019 96 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. pair<int, int> a[1000002];
  5. int b[1000002]; long long n, k, t, j, t1, t2;
  6. int main()
  7. {
  8.     cin >> n >> k;
  9.     for (int i = 1; i <= n; i++) {
  10.         cin >> t;  a[i].first = t;
  11.         a[i].second = i;
  12.     }
  13.     sort(a + 1, a + n + 1);
  14.     for (int i = 1; i <= n; i++) {
  15.         b[i] = a[i].first;
  16.     }
  17.     for (int i = 1; i <= n; i++) {
  18.         t1 = b[i] - k;
  19.         t2 = b[i] + k;
  20.         if (lower_bound(b + 1, b + n + 1, t1) < upper_bound(b + 1, b + n + 1, t1))
  21.         {
  22.             int vt = lower_bound(b + 1, b + n + 1, t1) - b;
  23.             cout << a[i].second << " " << a[vt].second;
  24.             return 0;
  25.         }
  26.         if (lower_bound(b + 1, b + n + 1, t2) < upper_bound(b + 1, b + n + 1, t2))
  27.         {
  28.             int vt = lower_bound(b + 1, b + n + 1, t2) - b;
  29.             cout << a[vt].second << " " << a[i].second;
  30.             return 0;
  31.         }
  32.     }
  33.     cout << "0 0";
  34.     return 0;
  35. }
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