#C6564. Maximizing Book Page Count Difference
Maximizing Book Page Count Difference
Maximizing Book Page Count Difference
Alice is obsessed with her book collection. She wants a diverse reading experience by choosing a set of contiguous books that exhibits the largest variation in page counts. Given a sequence of \(N\) books with page counts \(P_1, P_2, \ldots, P_N\), your task is to select exactly \(M\) consecutive books such that the difference between the maximum and minimum page counts in that segment is maximized.
Example: If Alice has books with page counts [150, 80, 200, 300, 50] and she chooses \(M = 3\), one possible segment is [200, 300, 50] which gives a difference of \(300 - 50 = 250\). This is the maximum difference that can be achieved.
inputFormat
The input begins with an integer \(T\) representing the number of test cases. Each test case is described as follows:
- The first line contains two space-separated integers \(N\) and \(M\), where \(1 \le N \le 100\) and \(1 \le M \le N\).
- The second line contains \(N\) space-separated integers \(P_i\) (\(1 \le P_i \le 10^9\)) representing the page counts of the books.
outputFormat
For each test case, output a single line containing the maximum difference between the maximum and minimum page counts among any contiguous segment of exactly \(M\) books.
## sample1
5 3
150 80 200 300 50
250
</p>