sort(arr, arr + n);

for(int i = 0; i < n-1; i++){

```
ll m=min(arr[i],arr[i+1]);
if(m<= k){
continue;
}
ll temp = m - k;
arr[i] = arr[i] - temp;
arr[i+1] = arr[i+1] - temp;
}
```

i have sorted the array and while elements are less than k continued and if min(arr[i],arr[i+1])>k then subtracted the difference and in last took sum of final array.

Can anyone help me to know my conceptual mistake.