103664: [Atcoder]ABC366 E - Manhattan Multifocal Ellipse

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:4 Solved:0

Description

Score : $475$ points

Problem Statement

You are given $N$ points $(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N)$ on a two-dimensional plane, and a non-negative integer $D$.

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

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $0 \leq D \leq 10^6$
  • $-10^6 \leq x_i, y_i \leq 10^6$
  • $(x_i, y_i) \neq (x_j, y_j)$ for $i \neq j$.
  • All input values are integers.

Input

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

$N$ $D$
$x_1$ $y_1$
$x_2$ $y_2$
$\vdots$
$x_N$ $y_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 $1$. 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

Output

得分:475分

问题陈述

在二维平面上给出N个点$(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N)$,以及一个非负整数$D$。

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

约束条件

  • $1 \leq N \leq 2 \times 10^5$
  • $0 \leq D \leq 10^6$
  • $-10^6 \leq x_i, y_i \leq 10^6$
  • 当$i \neq j$时,$(x_i, y_i) \neq (x_j, y_j)$。
  • 所有输入值都是整数。

输入

输入从标准输入以下格式给出:

$N$ $D$
$x_1$ $y_1$
$x_2$ $y_2$
$\vdots$
$x_N$ $y_N$

输出

打印答案。


样本输入1

2 3
0 0
1 0

样本输出1

8

下图对样本1的输入和答案进行了可视化。蓝色点代表输入。蓝色和红色点,共计八个,满足题目中的条件。


样本输入2

2 0
0 0
2 0

样本输出2

0

样本输入3

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

样本输出3

419

加入题单

上一题 下一题 算法标签: