luogu#P5244. [USACO19FEB] Mowing Mischief P

    ID: 4219 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2019线段树USACO动态规划优化决策单调性

[USACO19FEB] Mowing Mischief P

Problem Description

Bessie’s cousins, Ella and Bella, are visiting the farm. Unfortunately, ever since they arrived, they have been causing trouble.

In their latest scheme, they decide to mow as much grass as possible. The farm’s grassland is a T×TT \times T square. The lower-left corner is (0,0)(0,0), and the upper-right corner is (T,T)(T,T). Therefore, the square contains (T+1)2(T+1)^2 lattice points (points with integer coordinates).

Ella and Bella plan to start from (0,0)(0,0) and run to (T,T)(T,T) at a speed of one unit length per second. At the same time, each cow holds one end of a very sharp and very elastic wire. Any area swept by this wire will have its grass cut. Ella and Bella may take different paths, but they will only move up or right, traveling from one lattice point to another.

Bessie is very worried that too much grass will be cut, so she comes up with a clever plan to restrict Ella and Bella’s paths. There are NN flowers scattered across the grassland (1N2×1051 \leq N \leq 2 \times 10^5), and each flower is located at a specific lattice point. Bessie will choose a subset SS of these flowers. Both Ella and Bella must pass through all flowers in SS (that is, both of their paths must go through every flower in SS).

Ella and Bella will cut an area of grass as large as possible. Please help Bessie determine the set SS so that, while SS is as large as possible, the area of grass that gets cut is minimized.

Input Format

The first line contains two integers N,TN, T (1T1061 \leq T \leq 10^6).

The next NN lines each contain two integers xi,yix_i, y_i, representing the position of a flower.

It is guaranteed that 1xi,yiT11 \leq x_i, y_i \leq T-1, and no two flowers lie on the same horizontal or vertical line.

Output Format

Output one integer: the minimum possible area of grass that gets cut.

5 20
19 1
2 6
9 15
10 3
13 11
117

Hint

Choosing the flowers at positions (10,3)(10,3) and (13,11)(13,11) can minimize the area of grass that gets cut.

Subtasks: For 20%20\% of the testdata, N3200N \leq 3200.

Translated by ChatGPT 5