Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(NULL);
  12.  
  13. int n, k;
  14. cin >> n >> k;
  15. int* arr = new int[n];
  16. int counter = 0;
  17.  
  18.  
  19. for (int i = 0; i < n; i++)
  20. {
  21. cin >> arr[i];
  22. }
  23.  
  24. for (int i = 0; i < n; i++)
  25. {
  26. int min = arr[i];
  27. int max = arr[i];
  28. for (int j = i; j < n; j++)
  29. {
  30. int currentElement = arr[j];
  31. if (currentElement > max)
  32. {
  33. max = currentElement;
  34. }
  35. else if (currentElement < min)
  36. {
  37. min = currentElement;
  38. }
  39. if (max - min <= k)
  40. counter++;
  41.  
  42. }
  43. }
  44. cout << counter << "\n";
  45. system("pause");
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement