#P10561. [ICPC2024 Xi'an I] Smart Quality Inspector

[ICPC2024 Xi'an I] Smart Quality Inspector

题目描述

Ella has a factory. One day, her factory is facing a product quality inspection.

Her factory has NN production lines. Among the NN production lines, NKN-K of them are qualified, and the other KK lines are unqualified. The fine of the ii -th(1iK)(1\leq i\leq K) unqualified line is ii Yuan.

There are MM quality inspectors here. For the jj -th(1jM)(1\leq j\leq M) quality inspector, he will inspect from the lil_i -th line to the rir_i -th line and find the unqualified production line with the largest fine among them, then impose this fine on Ella.

Ella does not want to receive so many fines, so she decides to renumber the NN production lines to receive the least amount of fines. Please help her.

In simple terms:

You have a sequence AA of length NN, A=[1,2,3,...,K,0,0,0,...,0]A=[1,2,3,...,K,0,0,0,...,0]. Here N,KN,K are given.

There are MM pairs of integers, each pair consists of two numbers li,ril_i,r_i.

You need to rearrange sequence AA to minimize the following:

i=1Mmaxj=liri(Aj)\sum_{i=1}^M \max_{j=l_i}^{r_i} (A_{j})

输入格式

The first line contains three integers N,K,M(1KN20,1M105)N,K,M(1\leq K\leq N\leq 20,1\leq M\leq 10^5), described in the statement.

Then MM lines, the ii -th line of them contains two integers li,ri(1liriN)l_i,r_i(1\leq l_i\leq r_i\leq N).

输出格式

An integer indicates the answer.

4 4 3
1 2
3 4
1 4
10