#P7371. [COCI 2018/2019 #4] Kisik

[COCI 2018/2019 #4] Kisik

Description

The CAIN organization decided to build a new town on Mars for KK families, so it will build KK buildings, one for each family. For each family, CAIN provides NN different building designs to choose from.

All buildings are placed right next to each other so that their bottoms lie on the same straight line. After construction, the town needs to be inflated and kept inside a glass wall. The glass wall can only enclose a rectangular area, so the inflated region is also a rectangle.

Find the minimum amount of inflation required.

Input Format

The first line contains integers N,KN, K.

The next NN lines each contain integers Wi,HiW_i, H_i, representing the width and height of the ii-th building. It is guaranteed that there are no duplicate pairs (Wi,Hi)(W_i, H_i).

Output Format

Output the minimum amount of inflation required.

4 3
2 3
2 2
1 4
3 2
20
3 3
1 1
3 3
2 2
18
4 1
6 4
4 5
19 1
3 6
18

Hint

Explanation of Sample 1

This plan requires only 2020 units of inflation, which is the minimum:

Constraints

For the testdata worth 4040 points, N1000N \le 1000.

For 100%100\% of the testdata, 1KN1061 \le K \le N \le 10^6, 1Wi,Hi1061 \le W_i, H_i \le 10^6.

Notes

The score of this problem follows the original COCI setting, with a full score of 9090.

Translated from COCI2018-2019 CONTEST #4 T3 Kisik.

Translated by ChatGPT 5