#abc318f. F - Octopus

F - Octopus

Score : 575575 points

问题描述

在数轴上有一个章鱼形状的机器人和NN个宝藏。第ii个宝藏(1iN1\leq i\leq N)位于坐标XiX_i处。

该机器人有一个头部和NN条腿,其中第ii条腿(1iN1\leq i\leq N)的长度为LiL_i

找出满足以下条件的整数 kk的数量,使得机器人可以按照如下方式抓取所有NN个宝藏。

  • 将头部放置在坐标kk处。
  • 按照顺序依次对i=1,2,,Ni=1,2,\ldots,N执行以下操作:若存在一个尚未被抓住的宝藏,且其距离头部的距离在LiL_i以内,即存在一个坐标xx满足kLixk+Lik-L_i\leq x\leq k+L_i,则选择其中一个这样的宝藏并抓取它。

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

Problem Statement

There is an octopus-shaped robot and NN treasures on a number line. The ii-th treasure (1iN)(1\leq i\leq N) is located at coordinate XiX_i.
The robot has one head and NN legs, and the ii-th leg (1iN)(1\leq i\leq N) has a length of LiL_i.

Find the number of integers kk such that the robot can grab all NN treasures as follows.

  • Place the head at coordinate kk.
  • Repeat the following for i=1,2,,Ni=1,2,\ldots,N in this order: if there is a treasure that has not been grabbed yet within a distance of LiL_i from the head, that is, at a coordinate xx satisfying kLixk+Lik-L_i\leq x\leq k+L_i, choose one such treasure and grab it.

Constraints

  • 1N2001 \leq N\leq 200
  • 1018X1<X2<<XN1018-10^{18} \leq X_1<X_2<\cdots<X_N\leq 10^{18}
  • 1L1L2LN10181\leq L_1\leq L_2\leq\cdots\leq L_N\leq 10^{18}
  • All input values are integers.

Input

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

NN

X1X_1 X2X_2 \ldots XNX_N

L1L_1 L2L_2 \ldots LNL_N

Output

Print the number of integers kk that satisfy the condition in the statement.

Sample Input 1

3
-6 0 7
3 5 10

Sample Output 1

6

k=3,2,1,2,3,4k=-3,-2,-1,2,3,4 satisfy the condition. For example, when k=3k=-3, the robot can grab all three treasures as follows.

  • The first leg can grab treasures at coordinates xx satisfying 6x0-6\leq x\leq 0. Among them, grab the first treasure at coordinate 6-6.
  • The second leg can grab treasures at coordinates xx satisfying 8x2-8\leq x\leq 2. Among them, grab the second treasure at coordinate 00.
  • The third leg can grab treasures at coordinates xx satisfying 13x7-13\leq x\leq 7. Among them, grab the third treasure at coordinate 77.

Sample Input 2

1
0
1000000000000000000

Sample Output 2

2000000000000000001

All integers kk from 1018-10^{18} to 101810^{18} satisfy the condition.

Sample Input 3

2
-100 100
1 1

Sample Output 3

0

No kk satisfies the conditions.

update @ 2024/3/10 09:05:06