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
- int cnt[105];
- signed main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n , k;
- cin >> n >> k;
- int a[n + 5];
- for(int i = 0; i < n; i++){
- cin >> a[i];
- }
- multiset<int> ms;
- int l = 0 , ans = 0;
- for(int i = 0; i < n; i++){
- ms.insert(a[i]);
- while(*ms.rbegin() - *ms.begin() > k){
- ms.erase(ms.find(a[l]));
- l++;
- }
- ans += (i - l + 1);
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement