BPC 1 S6 - Painters

View as PDF

Submit solution


Points: 30 (partial)
Time limit: 3.0s
Memory limit: 256M

Authors:
Problem type

Rich with loot from the temple, you purchased a house and hired a team of workers to renovate it. This team has a strange way of painting. Instead of fully covering a wall with paint, like a normal crew, the i^\text{th} (1 \le i \le N) worker paints a rectangle whose lower-left corner is l_i, b_i and whose upper-right corner is r_i, t_i. Rectangles can overlap, and the crew won't necessarily cover the entire wall. You just arrived home and saw the workers painting a wall the wrong colour. You still have time to tell M (0 \le M \le 1) workers to stop and prevent them from painting their rectangle. Find the minimum possible area that will be covered when everyone is done painting.

Constraints

1 \le N \le 3 \times 10^5

1 \le l_i < r_i \le 10^6

1 \le b_i < t_i \le 10^6

Subtask 1 [10%]

1 \le N \le 2 \times 10^3

Subtask 2 [25%]

M = 0

Subtask 3 [65%]

No additional constraints.

Input Specification

The first line contains two integers, N and M.

The following N lines each contain four integers, l_i, b_i, r_i, t_i.

Output Specification

Output one line containing a single integer, the minimum area covered by paint.

Sample Input 1

3 0
1 1 3 3
2 2 4 4
5 1 7 7

Sample Output 1

19

Explanation for Sample 1

A total of 19 units will be covered by paint.

Sample 1 size 50%

Sample Input 2

4 1
2 2 5 7
4 1 6 5
3 3 5 8
6 5 8 8

Sample Output 2

22

Explanation for Sample 2

It is optimal to tell the first or fourth painter not to paint their rectangle.

Sample 2 size 50%


Comments

There are no comments at the moment.