102962: [Atcoder]ABC296 C - Gap Existence

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

Description

Score : $300$ points

Problem Statement

You are given a sequence of $N$ numbers: $A=(A_1,\ldots,A_N)$.

Determine whether there is a pair $(i,j)$ with $1\leq i,j \leq N$ such that $A_i-A_j=X$.

Constraints

  • $2 \leq N \leq 2\times 10^5$
  • $-10^9 \leq A_i \leq 10^9$
  • $-10^9 \leq X \leq 10^9$
  • All values in the input are integers.

Input

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

$N$ $X$
$A_1$ $\ldots$ $A_N$

Output

Print Yes if there is a pair $(i,j)$ with $1\leq i,j \leq N$ such that $A_i-A_j=X$, and No otherwise.


Sample Input 1

6 5
3 1 4 1 5 9

Sample Output 1

Yes

We have $A_6-A_3=9-4=5$.


Sample Input 2

6 -4
-2 -7 -1 -8 -2 -8

Sample Output 2

No

There is no pair $(i,j)$ such that $A_i-A_j=-4$.


Sample Input 3

2 0
141421356 17320508

Sample Output 3

Yes

We have $A_1-A_1=0$.

Input

题意翻译

有一个长度为 $n$ 的数组 $a$,给定一个数 $x$,确定是否存在一组 $(i,j)$ 满足 $a_i-a_j=x$。 Translated by @[Zealous_YH](https://www.luogu.com.cn/user/399150)

Output

得分:300分

问题描述

给你一个包含 $N$ 个数字的序列:$A=(A_1,\ldots,A_N)$。

确定是否存在一个对 $(i,j)$,满足 $1\leq i,j \leq N$ 且 $A_i-A_j=X$。

约束条件

  • $2 \leq N \leq 2\times 10^5$
  • $-10^9 \leq A_i \leq 10^9$
  • $-10^9 \leq X \leq 10^9$
  • 输入中的所有值都是整数。

输入

输入通过标准输入给出以下格式:

$N$ $X$
$A_1$ $\ldots$ $A_N$

输出

如果存在一个对 $(i,j)$,满足 $1\leq i,j \leq N$ 且 $A_i-A_j=X$,则输出 Yes,否则输出 No


样例输入 1

6 5
3 1 4 1 5 9

样例输出 1

Yes

我们有 $A_6-A_3=9-4=5$。


样例输入 2

6 -4
-2 -7 -1 -8 -2 -8

样例输出 2

No

不存在一对 $(i,j)$ 满足 $A_i-A_j=-4$。


样例输入 3

2 0
141421356 17320508

样例输出 3

Yes

我们有 $A_1-A_1=0$。

HINT

n种数字,每种至少2个,是否能找出两个数字之差为m?

加入题单

算法标签: