102970: [Atcoder]ABC297 A - Double Click
Description
Score : $100$ points
Problem Statement
Takahashi turned on a computer at time $0$ and clicked the mouse $N$ times. The $i$-th $(1 \le i \le N)$ click was at time $T_i$.
If he consecutively clicked the mouse at time $x_1$ and time $x_2$ (where $x_1 < x_2$), a double click is said to be fired at time $x_2$ if and only if $x_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
- $1 \le N \le 100$
- $1 \le D \le 10^9$
- $1 \le T_i \le 10^9(1 \le i \le N)$
- $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:
$N$ $D$ $T_1$ $T_2$ $\dots$ $T_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 $900$ and $1300$. Since $1300 - 900 \le 500$, a double click was fired at time $1300$.
A double click had not been fired before time $1300$, so $1300$ 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.
Input
题意翻译
给定一个长度为 $N$ 的单调上升的序列 $a$ 与正整数 $D$,求第一个 $i$($2\le i\le N$)使得 $a_i-a_{i-1}\le D$,输出 $a_i$。若这样的 $i$ 不存在,则输出 `-1`。Output
问题描述
高桥在时间0打开电脑并点击鼠标N次。第i次点击(1≤i≤N)发生的时间为Ti。
如果他在时间x1和时间x2(其中x1<x2)连续点击鼠标,那么当且仅当x2 - x1 ≤ D时,称在时间x2触发了双击。
第一次触发双击是什么时候?如果没有触发双击,则打印-1。
约束
- 1≤N≤100
- 1≤D≤109
- 1≤Ti≤109(1≤i≤N)
- Ti<Ti+1(1≤i≤N-1)
- 输入中的所有值都是整数。
输入
输入通过标准输入给出,如下所示:
$N$ $D$ $T_1$ $T_2$ $\dots$ $T_N$
输出
如果至少触发了一次双击,请打印第一次这样的事件的时间;否则,打印-1。
样例输入1
4 500 300 900 1300 1700
样例输出1
1300
高桥在时间900和1300点击了鼠标。由于1300 - 900 ≤ 500,因此在时间1300触发了双击。
在时间1300之前没有触发过双击,因此应该打印1300。
样例输入2
5 99 100 200 300 400 500
样例输出2
-1
没有触发双击,所以打印-1。
样例输入3
4 500 100 600 1100 1600
样例输出3
600
如果有多个触发的双击,务必只打印第一次这样的事件。