Help with approach

prob: https://codeforces.com/problemset/problem/1466/B

sol: https://ide.codingblocks.com/s/402898

hello @raghav007
increase ur array size (check constraints).

done still, not working

@raghav007
image
u r reading n+1 elements in total .

use i<n .

last example test case is failing ans shd be 3 it is giving 4

check now->

if previous < current then cnt++

else if previous ==current then we need to increase current by 1 and then cnt++

also update previous max in both the case

can you please explain the concept for the algorithm I’m not able to understand.

see given array is sorted.
so x[i]<=x[i+1] will always hold.

we can break this condition in x[i] == x[i+1] and x[i] < x[i+1] and then solve them seprately.

case x[i]< x[i+1] clealry we include x[i+1] so cnt++

case x[i]==x[i+1] here we need to increase x[i+1] by 1 to make x[i] < x[i+1] and then cnt++;