Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MAXN 100005
  4. int n, v[MAXN], L;
  5. int t[MAXN];
  6. int main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. cin >> n;
  10. for(int i = 1; i <= n; ++i) {
  11. cin >> v[i];
  12. }
  13. cin >> L;
  14. t[0] = t[1] = 0;
  15. for(int i = 2; i <= n; ++i) {
  16. for(int j = 1; j < i; ++j) {
  17. if(v[i] - v[j] <= L) {
  18. t[i] = t[j] + 1;
  19. break;
  20. }
  21. }
  22. }
  23.  
  24.  
  25. int q, a, b;
  26. cin >> q;
  27. while(q--) {
  28. cin >> a >> b;
  29. if(a > b) {
  30. swap(a,b);
  31. }
  32. if(t[a] == t[b])
  33. cout << 1 << endl;
  34. else
  35. cout << t[b] - t[a] << endl;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement