EDIT: Fix it by using SortedSet.GetViewBetween

```
public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) {
if(t < 0) return false;
SortedSet<long> ss = new SortedSet<long>();
for(int i = 0; i < nums.Length; i++){
if(ss.GetViewBetween((long)nums[i] - t, (long)nums[i] + t).Count > 0) return true;
ss.Add(nums[i]);
if(i >= k) ss.Remove(nums[i - k]);
}
return false;
}
```

Below is the old version of O(Log(N*K))

```
public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) {
SortedList<int, int> sdc = new SortedList<int, int>();
for (int i = 0; i < nums.Length && k != 0; i++){
for (int j = 0, l = sdc.Count - 1; j <= l;)
if ((long)nums[i] - (long)sdc.Keys[(j + l) / 2] > (long)t)
l = (j + l) / 2 - 1;
else if ((long)nums[i] - (long)sdc.Keys[(j + l) / 2] < -(long)t)
j = (j + l) / 2 + 1;
else return true;
if (sdc.Count == k)
sdc.RemoveAt(sdc.IndexOfValue(i - k));
sdc.Add(nums[i], i);
}
return false;
}
```