#P5574. [CmdOI2019] 任务分配问题

    ID: 6299 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DPO2优化分治凸完全单调性(wqs 二分)

[CmdOI2019] 任务分配问题

Background

What does it feel like to kick off the power cable while mining?

Problem Description

On a computer with kk CPUs, there are nn computing tasks waiting to be executed.

Let aia_i be the priority of the ii-th task. For convenience, aa 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 n,kn, k, representing the number of tasks and the number of CPUs.

The second line contains nn integers, representing a1na_{1\sim n}.

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 55.

  • Sample #2

    The first CPU processes task 11 alone, with disorder 00.

    The second CPU processes {5,4,2,3}\{5,4,2,3\}, with disorder 11.

Constraints and Notes

For all testdata, it is guaranteed that 1n2.5×1041\leq n\leq 2.5\times 10^4, 1k251\leq k\leq 25, ana\leq n.

Test Point ID nn kk
121\sim 2 2.5×1042.5\times 10^4 11
33 22
454\sim 5 10001000 1010
6106\sim 10 2.5×1042.5\times 10^4 2525

Translated by ChatGPT 5