Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define fst first
  4. #define snd second
  5. typedef long long ll;
  6. typedef unsigned long long ull;
  7.  
  8. using namespace std;
  9. typedef pair<int, int> ii;
  10. typedef pair<int, ii> iii;
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(false);
  15.     cin.tie(0), cout.tie(0);
  16.     int n, k, l, r;
  17.     cin >> n >> k >> l >> r;
  18.     vector<int> a(n);
  19.     for (int& i : a)
  20.         cin >> i;
  21.     set<ii> t = {{a[0], 0}};
  22.     for (int i = 1; i < n; ++i) {
  23.         auto a_j1 = t.lower_bound({a[i] - r, 0}),
  24.             a_j2 = t.lower_bound({a[i] + l, 0});
  25.         if (a_j1 != t.end() && abs(a[i] - a_j1->fst) >= l && abs(a[i] - a_j1->fst) <= r) {
  26.             cout << a_j1->snd + 1 << ' ' << i + 1;
  27.             return 0;
  28.         } else if (a_j2 != t.end() && abs(a[i] - a_j2->fst) >= l && abs(a[i] - a_j2->fst) <= r) {
  29.             cout << a_j2->snd + 1 << ' ' << i + 1;
  30.             return 0;
  31.         }
  32.         if (i >= k)
  33.             t.erase({a[i - k], i - k});
  34.         t.insert({a[i], i});
  35.     }
  36.     cout << "-1 -1";
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement