#P5574. [CmdOI2019] 任务分配问题
[CmdOI2019] 任务分配问题
Background
What does it feel like to kick off the power cable while mining?
Problem Description
On a computer with CPUs, there are computing tasks waiting to be executed.
Let be the priority of the -th task. For convenience, is a permutation.
Now, these tasks need to be assigned to the CPUs to be processed.
Due to reasons such as memory limits, one CPU can only handle one continuous segment of tasks, and it must execute them in order (from left to right).
Within a single CPU, the disorder is defined as the number of pairs of tasks where the former is executed earlier, but the latter has a higher priority.
Minimize the sum of disorders over all CPUs.
Input Format
The first line contains two integers , representing the number of tasks and the number of CPUs.
The second line contains integers, representing .
Output Format
Output one integer, representing the minimum possible sum of disorders.
5 1
1 5 4 2 3
5
5 2
1 5 4 2 3
1
8 3
1 3 5 2 7 4 8 6
4
Hint
Sample Explanation
-
Sample #1
In this case, all tasks can only be assigned to a single CPU.
The first task forms disorder pairs with all other tasks; the last two tasks also form a disorder pair, for a total of .
-
Sample #2
The first CPU processes task alone, with disorder .
The second CPU processes , with disorder .
Constraints and Notes
For all testdata, it is guaranteed that , , .
| Test Point ID | ||
|---|---|---|
Translated by ChatGPT 5