if ((b == 0) && (arr[j] >= (arr[0] + D))) {
a = a + arr[j] - arr[0];
b = 1;
arr[0] = arr[j];
}
else if((b == 1) && (arr[0] - D) >= arr[j]) {
b = 0;