```
class Solution:
# @param {integer[]} nums
# @param {integer} k
# @param {integer} t
# @return {boolean}
def containsNearbyAlmostDuplicate(self, nums, k, t):
nums = [(nums[i], i) for i in range(0, len(nums))]
nums.sort(key=lambda x: x[0])
for i in range(1, len(nums)):
if nums[i][0] - nums[i - 1][0] <= t and abs(nums[i][1] - nums[i - 1][1]) <= k:
return True
return False
```