my thoughts are pretty straightforward, there are three states in this question:
state=0, ratings go all the way down;
state=1, ratings equal;
state=2, ratings go all the way up;
the only thing I have to pay attention to is if state goes from state 2 to 0, which forms a peak, then the peak should has more candies than both neighbors, which I keep track of the left side value, if the right side doesn't exceed , then the peak value doesn't need to add up.

this runtime is over 400ms, and i can see that most solutions are 200-300ms, so anyone would like to share that with me? thanks