#P10235. [yLCPC2024] C. 舞萌基本练习
[yLCPC2024] C. 舞萌基本练习
Problem Description
While playing MaiMai dx, Fusu found that a song can be split into at most segments for separate practice.
Specifically, the song has notes, and each note has a difficulty value. The difficulty of the -th note is . Fusu thinks that the notes in a segment should become as difficult as possible. Therefore, for an interval of the note sequence, she defines the “non-beauty” of this interval as the number of inversion pairs in this interval.
The number of inversion pairs in an interval is defined as the number of pairs such that and .
Fusu wants to partition the song into at most subsegments, so that every note belongs to at least one subsegment, and the maximum non-beauty among all segments is as small as possible.
Formally, you need to split it into intervals , satisfying:
- , .
- For , .
- For , .
Let denote the non-beauty of interval . Minimize .
Input Format
This problem contains multiple test cases within a single test file. The first line contains a positive integer , the number of test cases. For each test case:
The first line contains two integers (), representing the number of notes in the song and the maximum number of segments.
The second line contains integers (), representing the difficulty of each note.
It is guaranteed that the sum of over all test cases within a single test file does not exceed .
Output Format
For each test case, output one line with one integer, representing the answer.
2
5 2
1 3 2 5 4
8 2
4 2 3 6 7 1 8 5
1
2
Hint
Translated by ChatGPT 5