Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n, k;
- cin >> n >> k;
- int* arr = new int[n];
- int counter = 0;
- for (int i = 0; i < n; i++)
- {
- cin >> arr[i];
- }
- for (int i = 0; i < n; i++)
- {
- int min = arr[i];
- int max = arr[i];
- for (int j = i; j < n; j++)
- {
- int currentElement = arr[j];
- if (currentElement > max)
- {
- max = currentElement;
- }
- else if (currentElement < min)
- {
- min = currentElement;
- }
- if (max - min <= k)
- counter++;
- }
- }
- cout << counter << "\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement