Delivery#10955

Delivery

1,5 Sekunden
256 Megabyte
Leicht

Mathew is the owner of a delivery company. He lives in a city where there are exactly 10^{9} houses ordered in a line. Each house has a number, and the house with number is adjacent to houses with numbers i - 1 and i + 1 (if they exist). Mathew's company has received queries for a delivery at house H_{i} at time exactly T_{i}. There are no two queries that are at the same time and at the same house. To save money, Mathew wants to know how many delivery trucks he will need to complete all the queries. The trucks he will buy can move 1 house to the left or the right in one unit of time (they can also stay at the same house). In the beginning, the trucks can be parked in front of whichever houses the owner chooses. In addition, the time for delivery is negligible.

Mathew is a busy man and has no time for easy tasks like this one so he asks you to write a program delivery.cpp that finds the minimum number of delivery trucks he will need.

Eingabe

From the first line of the standard input, your program should read one integer – the number of queries. Each of the next lines will contain two integers T_{i} and H_{i} – the time and house the delivery should happen at.

Ausgabe

On a single line, your program should output the minimum number of delivery trucks that are needed.

Beispiele

Beispiel 1

Loading
Loading

Notiz

The minimum number of delivery trucks we need is 2. One way to complete all deliveries is:

First truck: (1, 1)^* \to (2, 1) \to (3, 1) \to (4, 1)^* \to (5, 1)

Second truck: (1, 2) \to (2, 3)^* \to (3, 2)^* \to (4, 3)^* \to (5, 4)^*

Where represents the truck being at house at time , and are times on which the truck makes a delivery.

Bewertung

1 \leq N \leq 10^{6}
1 \leq T_{i}, H_{i} \leq 10^{9}
T_{i} \neq T_{j} \text{ or } H_{i} \neq H_{j} \text{ for } i \neq j

Subtask

Points

1

25

\leq 10^{3}

2

10

\leq 10^{4}

3

40

\leq 2 \times 10^{5}

4

20

\leq 10^{6}