Message from C, C++ talks
Inside of if
p[i] > pre we probably need to check that p[i] <= p[i-1] and only in this case increment
But then the result is going to be smaller by one if it's non-zero.
I think we can just do something like
if (count != 0) count++;
Before returning the value.
I think it can be made more elegantly than this, but I'm too lazy to think now.
Also, you need a check in case the vector is empty, not to crash.