P27498 [AtCoder] Amusement Park
提高+
题目描述

Problem Description

Takahashi has come to an amusement park. The park has $ N $ attractions lined up in a row, numbered $ 1, 2, ..., N $ in order.

Additionally, playing in this park requires stamina, and moving between adjacent attractions consumes $ 1 $ unit of stamina. Furthermore, playing the $ i $-th attraction requires at least $ L_i $ units of stamina, and after playing, the stamina will be exactly $ R_i $. Note that some attractions, due to their interestingness, may increase stamina after playing.

Takahashi wants to play as many types of attractions as possible. Determine the maximum number of types of attractions Takahashi can play by choosing the initial attraction and the subsequent order wisely. Note that Takahashi is initially in a very good mood and can be assumed to have infinite stamina.

Input Format

The input is given from the standard input in the following format:

$ N $ $ L_1 $ $ L_2 $ $ ... $ $ L_N $ $ R_1 $ $ R_2 $ $ ... $ $ R_N $

Output Format

Output the maximum number of types of attractions Takahashi can play.

Sample Input and Output

Sample Input #1

3
5 1 3
1 2 4

Sample Output #1

2

Sample Input #2

5
3 1 2 4 5
2 5 4 1 3

Sample Output #2

3

Notes/Hints

Constraints

  • $1 \leq N \leq 50,000$
  • $1 \leq L_i \leq 10^9$
  • $1 \leq R_i \leq 10^9$

Sample Explanation 1

If Takahashi plays the $ 3 $-th attraction first and then the $ 2 $-th attraction, he can play $ 2 $ types of attractions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 5 1 3 1 2 4
样例输出
2