#abc325d. D - Printing Machine

D - Printing Machine

Score : 450450 points

问题描述

NN个产品在传送带上流动,编号为1到NN。传送带上连接了一台基恩士打印机,第ii个产品将在TiT_i微秒后进入打印机的打印范围,并在DiD_i微秒后离开该范围。

基恩士打印机能够在打印范围内立即对一个产品进行打印(特别是,当产品进入或离开打印范围时可以立即打印)。但是,在完成一次打印后,需要充电时间为11微秒才能再次进行打印。当选择最优的产品和打印时机时,打印机最多能打印多少个产品?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN products labeled 11 to NN flowing on a conveyor belt. A Keyence printer is attached to the conveyor belt, and product ii enters the range of the printer TiT_i microseconds from now and leaves it DiD_i microseconds later.

The Keyence printer can instantly print on one product within the range of the printer (in particular, it is possible to print at the moment the product enters or leaves the range of the printer). However, after printing once, it requires a charge time of 11 microseconds before it can print again. What is the maximum number of products the printer can print on when the product and timing for the printer to print are chosen optimally?

Constraints

  • 1N2×1051\leq N \leq 2\times 10^5
  • 1Ti,Di10181\leq T_i,D_i \leq 10^{18}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

T1T_1 D1D_1

T2T_2 D2D_2

\vdots

TNT_N DND_N

Output

Print the maximum number of products the printer can print on.

Sample Input 1

5
1 1
1 1
2 1
1 2
1 4

Sample Output 1

4

Below, we will simply call the moment tt microseconds from now time tt.

For example, you can print on four products as follows:

  • Time 11 : Products 1,2,4,51,2,4,5 enter the range of the printer. Print on product 44.
  • Time 22 : Product 33 enters the range of the printer, and products 1,21,2 leave the range of the printer. Print on product 11.
  • Time 33 : Products 3,43,4 leave the range of the printer. Print on product 33.
  • Time 4.54.5 : Print on product 55.
  • Time 55 : Product 55 leaves the range of the printer.

It is impossible to print on all five products, so the answer is 44.

Sample Input 2

2
1 1
1000000000000000000 1000000000000000000

Sample Output 2

2

Sample Input 3

10
4 1
1 2
1 4
3 2
5 1
5 1
4 1
2 1
4 1
2 4

Sample Output 3

6

update @ 2024/3/10 01:48:04