Advertisement
Egor_1425

Untitled

Mar 15th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. n, r = map(int, input().split())
  2. a = list(map(int, input().split()))
  3.  
  4. left, right, count = 0, 1, 0
  5. while right < n and left < n - 1:
  6.     if a[right] - a[left] <= r:
  7.         right += 1
  8.     else:
  9.         count += n - right
  10.         left += 1
  11.  
  12. print(count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement