公式

B - 相場の値動き / Market Price Movements 解説 by admin

swe-2-high

Day \(i\) (\(i \geq 2\)) is classified purely by comparing \(A_i\) with the previous day’s price \(A_{i-1}\): up if \(A_i > A_{i-1}\), down if \(A_i < A_{i-1}\), and flat if they are equal. The program reads the prices into an array, then for each \(i\) from \(1\) to \(N-1\) compares the adjacent pair and increments exactly one of three counters. Every day from day 2 to day \(N\) is classified exactly once into one of the three categories, so the counters match the problem’s definitions. The running time is \(O(N)\) and the array uses \(O(N)\) space (keeping only the previous day’s price would reduce this to \(O(1)\)).