E - Manhattan Multifocal Ellipse Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 475475

問題文

22 次元平面上の NN 個の点 (x1,y1),(x2,y2),,(xN,yN)(x_1,y_1),(x_2,y_2),\dots,(x_N,y_N) と、非負整数 DD が与えられます。

整数の組 (x,y)(x,y) であって、 i=1N(xxi+yyi)D\displaystyle \sum_{i=1}^N (|x-x_i|+|y-y_i|) \leq D を満たすものの個数を求めてください。

制約

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0D1060 \leq D \leq 10^6
  • 106xi,yi106-10^6 \leq x_i, y_i \leq 10^6
  • iji\neq j ならば (xi,yi)(xj,yj)(x_i,y_i) \neq (x_j,y_j)
  • 入力はすべて整数

入力

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

NN DD
x1x_1 y1y_1
x2x_2 y2y_2
\vdots
xNx_N yNy_N

出力

答えを出力せよ。


入力例 1Copy

Copy
2 3
0 0
1 0

出力例 1Copy

Copy
8

下図は、サンプル 11 の入力と答えを可視化したものです。青い点が入力を表します。青い点と赤い点の合計 88 点が、問題文中の条件を満たす点です。


入力例 2Copy

Copy
2 0
0 0
2 0

出力例 2Copy

Copy
0

入力例 3Copy

Copy
6 100
9 -6
10 -1
2 10
-1 7
-7 5
-1 -4

出力例 3Copy

Copy
419

Score : 475475 points

Problem Statement

You are given NN points (x1,y1),(x2,y2),,(xN,yN)(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N) on a two-dimensional plane, and a non-negative integer DD.

Find the number of integer pairs (x,y)(x, y) such that i=1N(xxi+yyi)D\displaystyle \sum_{i=1}^N (|x-x_i|+|y-y_i|) \leq D.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0D1060 \leq D \leq 10^6
  • 106xi,yi106-10^6 \leq x_i, y_i \leq 10^6
  • (xi,yi)(xj,yj)(x_i, y_i) \neq (x_j, y_j) for iji \neq j.
  • All input values are integers.

Input

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

NN DD
x1x_1 y1y_1
x2x_2 y2y_2
\vdots
xNx_N yNy_N

Output

Print the answer.


Sample Input 1Copy

Copy
2 3
0 0
1 0

Sample Output 1Copy

Copy
8

The following figure visualizes the input and the answer for Sample 11. The blue points represent the input. The blue and red points, eight in total, satisfy the condition in the statement.


Sample Input 2Copy

Copy
2 0
0 0
2 0

Sample Output 2Copy

Copy
0

Sample Input 3Copy

Copy
6 100
9 -6
10 -1
2 10
-1 7
-7 5
-1 -4

Sample Output 3Copy

Copy
419


2025-04-28 (Mon)
12:14:28 +00:00