#abc297a. A - Double Click

A - Double Click

Score : 100100 points

问题描述

Takahashi 在时间 00 开启了一台计算机,并在不同时间点击了鼠标共 NN 次。第 ii 次(1iN1 \le i \le N)的点击发生在时间 TiT_i

若他在时间 x1x_1 和时间 x2x_2(其中 x1<x2x_1 < x_2)连续点击鼠标,如果满足 x2x1Dx_2 - x_1 \le D,则称在时间 x2x_2 发生了一次双击。

请问第一次双击发生的时间是什么?如果没有发生过双击,则输出 -1

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi turned on a computer at time 00 and clicked the mouse NN times. The ii-th (1iN)(1 \le i \le N) click was at time TiT_i.

If he consecutively clicked the mouse at time x1x_1 and time x2x_2 (where x1<x2x_1 < x_2), a double click is said to be fired at time x2x_2 if and only if x2x1Dx_2 - x_1 \le D.

What time was a double click fired for the first time? If no double click was fired, print -1 instead.

Constraints

  • 1N1001 \le N \le 100
  • 1D1091 \le D \le 10^9
  • 1Ti109(1iN)1 \le T_i \le 10^9(1 \le i \le N)
  • Ti<Ti+1(1iN1)T_i < T_{i+1}(1 \le i \le N-1)
  • All values in the input are integers.

Input

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

NN DD

T1T_1 T2T_2 \dots TNT_N

Output

If at least one double click was fired, print the time of the first such event; otherwise, print -1.

Sample Input 1

4 500
300 900 1300 1700

Sample Output 1

1300

Takahashi clicked the mouse at time 900900 and 13001300. Since 13009005001300 - 900 \le 500, a double click was fired at time 13001300.

A double click had not been fired before time 13001300, so 13001300 should be printed.

Sample Input 2

5 99
100 200 300 400 500

Sample Output 2

-1

No double click was fired, so print -1.

Sample Input 3

4 500
100 600 1100 1600

Sample Output 3

600

If multiple double clicks were fired, be sure to print only the first such event.

update @ 2024/3/10 12:19:41