#P5542. Painting the Barn
Painting the Barn
Painting the Barn
Farmer John is easily distracted and finds it difficult to complete long projects. Currently, he is painting one side of his barn, but instead of painting the whole surface uniformly, he paints small rectangular areas at a time. Due to his various distractions, some parts of the barn end up with more layers of paint than others.
The barn side can be modeled as a 2D x-y plane. Farmer John paints n rectangles on this plane, each rectangle having sides parallel to the coordinate axes and defined by the coordinates of its bottom-left and top-right corners. He ultimately wishes to have exactly K coats of paint on the barn, as this is the optimal number to avoid wasting paint.
Your task is to compute the total area that is covered by exactly K layers of paint after all rectangles have been processed.
Note: Any formulas must be formatted in LaTeX. For instance, the plane is described as the $x$-$y$ plane, and the number of rectangles is denoted by $n$, and the optimal paint coats by $K$.
inputFormat
The first line contains two integers $n$ and $K$, where $n$ is the number of rectangles, and $K$ is the desired number of paint coats.
Each of the following $n$ lines contains four integers $x_1$, $y_1$, $x_2$, and $y_2$, representing the bottom-left and top-right coordinates of a rectangle.
outputFormat
Output a single integer representing the total area of the barn side that is covered by exactly $K$ layers of paint.
sample
1 1
0 0 10 10
100
</p>