Advertisement
serega1112

Che

Jan 28th, 2022
1,145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n, r = map(int, input().split())
  2. nums = list(map(int, input().split()))
  3.  
  4. p1 = p2 = res =0
  5.  
  6. while p2 < n:
  7.     if nums[p2] - nums[p1] <= r:
  8.         p2 += 1
  9.     else:
  10.         res += n - p2
  11.         p1 += 1
  12.  
  13. print(res)
  14.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement