#abc366e. E - Manhattan Multifocal Ellipse

E - Manhattan Multifocal Ellipse

Score : 475475 points

问题陈述

给定二维平面上的 NN 个点 (x1,y1),(x2,y2),,(xN,yN)(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N),以及一个非负整数 DD

找出满足 $\displaystyle \sum_{i=1}^N (|x-x_i|+|y-y_i|) \leq D$ 的整数对 (x,y)(x, y) 的数量。

以上为大语言模型 kimi 翻译,仅供参考。

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 $\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 1

2 3
0 0
1 0

Sample Output 1

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 2

2 0
0 0
2 0

Sample Output 2

0

Sample Input 3

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

Sample Output 3

419