atcoder#AGC049C. [AGC049C] Robots

[AGC049C] Robots

Score : 800800 points

Problem Statement

There are robots on a number line. Specifically, for each i=0,1,2,,10100i=0,1,2,\cdots,10^{100}, there is exactly one robot called Robot ii at coordinate ii.

We have many balls. Each of the balls has a positive integer written on it. Integer sequences AA and BB, each of length NN, describe these balls. Specifically, for each ii (1iN1 \leq i \leq N), there are BiB_i balls with AiA_i written on them.

Now, Snuke will do the following sequence of operations:

  • Step 1: Choose zero or more balls and replace the integers written on those balls with positive integers of his choice between 11 and 1010010^{100} (inclusive). (The new integers can be chosen independently from each other.)
  • Step 2: Eat the balls one by one in any order of his choice. Each time he eats a ball, he should do the following:
    • Let vv be the integer written on the ball he has just eaten. If Robot vv exists, move it so that its coordinate decreases by 11. Here, if there is another robot at the destination, that robot (not Robot vv) will be destroyed.
  • Let vv be the integer written on the ball he has just eaten. If Robot vv exists, move it so that its coordinate decreases by 11. Here, if there is another robot at the destination, that robot (not Robot vv) will be destroyed.

Snuke wants to eat all the balls without destroying Robot 00. Find the minimum number of balls Snuke must choose in Step 1 to achieve his objective.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1A1<A2<<AN1091 \leq A_1 < A_2 < \ldots < A_N \leq 10^9
  • 1Bi1091 \leq B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BNB_N

Output

Print the answer.

3
1 2 3
1 2 1
1

We can achieve the objective by choosing one ball with 22 written on it, rewriting 33 on it, and then eating the balls in the following order:

  • Eat the ball with 22 written on it, moving Robot 22 from coordinate 22 to coordinate 11 and destroying Robot 11.
  • Eat the ball with 33 written on it, moving Robot 33 from coordinate 33 to coordinate 22.
  • Eat the ball with 33 written on it, moving Robot 33 from coordinate 22 to coordinate 11 and destroying Robot 22.
  • Eat the ball with 11 written on it. Robot 11 is already destroyed, so nothing happens.
4
1 3 5 7
3 1 4 1
0