#C558. Count Increasing and Decreasing Subsequences

    ID: 49244 Type: Default 1000ms 256MiB

Count Increasing and Decreasing Subsequences

Count Increasing and Decreasing Subsequences

You are given a list of temperature readings and an integer \(K\). Your task is to determine the total number of contiguous subsequences of length exactly \(K\) that are strictly increasing or strictly decreasing.

A sequence \(a_1, a_2, \dots, a_K\) is called strictly increasing if \(a_i < a_{i+1}\) for all \(1 \leq i a_{i+1}\) for all \(1 \leq i < K\). Note that these subsequences must appear consecutively in the list.

For example, if the readings are [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] and \(K=3\), each contiguous subsequence of length 3 is strictly decreasing, so the answer is 8.

inputFormat

The first line contains two space-separated integers: \(n\) (the number of temperature readings) and \(K\) (the length of the subsequences to examine).

The second line contains \(n\) space-separated integers representing the temperature readings.

outputFormat

Output a single integer representing the total number of contiguous subsequences of length \(K\) that are strictly increasing or strictly decreasing.

## sample
10 3
10 9 8 7 6 5 4 3 2 1
8

</p>