```
#ingclude <stdlib.h>
bool containsNearbyAlmostDuplicate(int* nums, int numsSize, int k, int t) {
int i,j;
long max,min;
if (numsSize == 1 || k <= 0 || t < 0 ) {
return false;
}
j = 0;
max = nums[j] + t;
min = nums[j] - t;
for (i=j+1; i < numsSize; i++){
if (nums[i] >= min && nums[i] <= max) {
return true;
}
if (i == j + k || i == numsSize - 1){
j = j + 1;
max = nums[j] + t;
min = nums[j] - t;
i = j + 1;
}
}
return false;
```

}