P12148 【MX-X11-T2】So I Gave Up on Music

Background

原题链接:。 --- $$\text{考えたってわからないし}$$ $$\text{青空の下、君を待った}$$ $$\text{風が吹いた正午、昼下がりを抜け出す想像}$$ $$\text{ねぇ、これからどうなるんだろうね}$$ $$\text{進め方教わらないんだよ}$$

Description

On an infinite chessboard, there are $n$ **distinct** pieces at positions $(x_i, y_i)$. You must delete all pieces by performing the following operation multiple times: 1. Choose a grid $(x, y)$. 2. If there is a piece at $(x, y)$, delete it. Otherwise, end the current operation. 3. **Sequentially** check the grids at $(x+1, y+1)$, $(x+1, y)$, and $(x+1, y-1)$. Upon finding the first grid with a piece, stop checking, update $(x, y)$ to this grid's coordinates, and return to Step 2. If none of these grids contain a piece, end the current operation. Determine the minimum number of operations required to delete all pieces.

Input Format

The first line contains a positive integer $n$ indicating the number of pieces. The next $n$ lines each contain two positive integers $x_i$, $y_i$ representing the coordinates of a piece. **All positions are guaranteed to be distinct**.

Output Format

Output a single positive integer representing the minimum number of operations needed.

Explanation/Hint

## Explanation #1 For the first sample, the chessboard is shown below: ![](https://cdn.luogu.com.cn/upload/image_hosting/8glrwdcs.png) - First operation: Choose $(1, 3)$. This deletes the pieces at $(1, 3)$, $(2, 2)$, and $(3, 3)$. - Second operation: Choose $(3, 1)$. This deletes the piece at $(3, 1)$. It can be proven that no better strategy exists. ## Constraints **This problem uses subtask scoring.** For all test data: $1 \le n \le 10^6$, $1 \le x_i, y_i \le 10^6$. | Subtask | $n \le$ | $x_i, y_i \le$ | Special Property | Points | |:---------:|:---------------:|:----------------:|:-------------------:|:--------:| | 1 | $10^6$ | $10^6$ | A | 10 | | 2 | $8$ | $10^6$ | None | 20 | | 3 | $300$ | $300$ | None | 20 | | 4 | $5 \times 10^4$ | $5 \times 10^4$ | None | 20 | | 5 | $10^6$ | $10^6$ | None | 30 | - **Special Property A**: All $x_i$ are equal. Translated by DeepSeek R1