Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define F first
- #define S second
- signed main()
- {
- int n , k;
- cin >> n >> k;
- int a[n + 5];
- for(int i = 0; i < n; i++){
- cin >> a[i];
- }
- int l = 0;
- multiset<int> ms;
- int ans = 0;
- for(int r = 0; r < n; r++){
- ms.insert(a[r]);
- while(*ms.rbegin() - *ms.begin() > k){
- ms.erase(ms.find(a[l]));
- l++;
- }
- ans += (r - l + 1);
- }
- cout << ans << '\n';
- }
- /*
- ms.erase(x); // butun x lari silir
- ms.erase(ms.find(x)) // bir x silir
- 3 1 2 6 4
- 1 2 3 1 2
- 1 2 3 3 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement