看官方题解的做法二
证明;
利用几何
假设当前在位置\(i\),不妨设\(a_{i+1}>a_i\),假设接下来数列长成这个样子:
可以发现无论怎么跳都会跳到\(a_j\),所以不如一步跳到
官方题解里面说的"stack"就是单调栈