F - Octopus Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 575575

問題文

数直線上に 11 体のタコ型ロボットと NN 個の宝があります。 ii (1iN)(1\leq i\leq N) 個目の宝はそれぞれ座標 XiX_i にあります。
タコ型ロボットは 11 つの頭と NN 本の足を持っており、ii 本目の足の長さは LiL_i (1iN)(1\leq i\leq N) です。

タコ型ロボットが次のようにして NN 個の宝すべてを掴む事ができるような整数 kk の個数を求めてください。

  • 頭を座標 kk におく。
  • i=1,2,,Ni=1,2,\ldots,N の順に、「頭から距離 LiL_i 以下の範囲、すなわち kLixk+Lik-L_i\leq x\leq k+L_i をみたす座標 xx にまだ掴んでいない宝が存在する場合、そのうちの 11 つを選んで掴む」ことを繰り返す。

制約

  • 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}
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN
X1X_1 X2X_2 \ldots XNX_N
L1L_1 L2L_2 \ldots LNL_N

出力

問題文の条件をみたす整数 kk の個数を出力せよ。


入力例 1Copy

Copy
3
-6 0 7
3 5 10

出力例 1Copy

Copy
6

k=3,2,1,2,3,4k=-3,-2,-1,2,3,4 が条件をみたします。例えば、k=3k=-3 のときは、次のようにして 33 個の宝をすべて掴む事ができます。

  • 11 本目の足は 6x0-6\leq x\leq 0 にある宝を掴む事ができる。このうち座標 6-6 にある 11 個目の宝を掴む。
  • 22 本目の足は 8x2-8\leq x\leq 2 にある宝を掴む事ができる。このうち座標 00 にある 22 個目の宝を掴む。
  • 33 本目の足は 13x7-13\leq x\leq 7 にある宝を掴む事ができる。このうち座標 77 にある 33 個目の宝を掴む。

入力例 2Copy

Copy
1
0
1000000000000000000

出力例 2Copy

Copy
2000000000000000001

1018-10^{18} 以上 101810^{18} 以下のすべての整数が kk として条件をみたします。


入力例 3Copy

Copy
2
-100 100
1 1

出力例 3Copy

Copy
0

条件をみたす kk は存在しません。

Score : 575575 points

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 1Copy

Copy
3
-6 0 7
3 5 10

Sample Output 1Copy

Copy
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 2Copy

Copy
1
0
1000000000000000000

Sample Output 2Copy

Copy
2000000000000000001

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


Sample Input 3Copy

Copy
2
-100 100
1 1

Sample Output 3Copy

Copy
0

No kk satisfies the conditions.



2025-04-28 (Mon)
17:08:05 +00:00