103760: [Atcoder]ABC376 A - Candy Button
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:31
Solved:0
Description
Score : $150$ points
Problem Statement
There is a mysterious button. When you press this button, you receive one candy, unless less than $C$ seconds have elapsed since you last received a candy.
Takahashi decided to press this button $N$ times. He will press the button for the $i$-th time $T_i$ seconds from now.
How many candies will he receive?
Constraints
- $1 \leq N \leq 100$
- $1 \leq C \leq 1000$
- $0 \leq T_1 < T_2 < \dots < T_N \leq 1000$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
$N$ $C$ $T_1$ $T_2$ $\dots$ $T_N$
Output
Print the number of candies that Takahashi will receive.
Sample Input 1
6 5 1 3 7 8 10 12
Sample Output 1
3
Takahashi will press the button six times.
- 1st press ($1$ second from now): You always receive a candy when pressing the button for the first time.
- 2nd press ($3$ seconds from now): $3 - 1 = 2 < C$ seconds have elapsed since he last received a candy, so he does not receive a candy.
- 3rd press ($7$ seconds from now): $7 - 1 = 6 \geq C$ seconds have elapsed since he last received a candy, so he receives a candy.
- 4th press ($8$ seconds from now): $8 - 7 = 1 < C$ second has elapsed since he last received a candy, so he does not receive a candy.
- 5th press ($10$ seconds from now): $10 - 7 = 3 < C$ seconds have elapsed since he last received a candy, so he does not receive a candy.
- 6th press ($12$ seconds from now): $12 - 7 = 5 \geq C$ seconds have elapsed since he last received a candy, so he receives a candy.
Therefore, he receives three candies.
Sample Input 2
3 2 0 2 4
Sample Output 2
3
Sample Input 3
10 3 0 3 4 6 9 12 15 17 19 20
Sample Output 3
7
Output
得分:150分
问题陈述
有一个神秘的按钮。 当你按下这个按钮时,你会得到一颗糖果,除非自你上次得到糖果以来还不到$C$秒。
高桥决定按这个按钮$N$次。 他将从现在开始$T_i$秒后第$i$次按下按钮。
他将得到多少颗糖果?
约束条件
- $1 \leq N \leq 100$
- $1 \leq C \leq 1000$
- $0 \leq T_1 < T_2 < \dots < T_N \leq 1000$
- 所有输入值都是整数。
输入
输入将从标准输入以下格式给出:
$N$ $C$ $T_1$ $T_2$ $\dots$ $T_N$
输出
打印高桥将收到的糖果数量。
样本输入1
6 5 1 3 7 8 10 12
样本输出1
3
高桥将按六次按钮。
- 第一次按(现在起1秒后):第一次按按钮时,你总是能得到一颗糖果。
- 第二次按(现在起3秒后):从他上次得到糖果到现在已经过去了$3 - 1 = 2$秒,小于$C$,所以他得不到糖果。
- 第三次按(现在起7秒后):从他上次得到糖果到现在已经过去了$7 - 1 = 6$秒,大于等于$C$,所以他得到一颗糖果。
- 第四次按(现在起8秒后):从他上次得到糖果到现在已经过去了$8 - 7 = 1$秒,小于$C$,所以他得不到糖果。
- 第五次按(现在起10秒后):从他上次得到糖果到现在已经过去了$10 - 7 = 3$秒,小于$C$,所以他得不到糖果。
- 第六次按(现在起12秒后):从他上次得到糖果到现在已经过去了$12 - 7 = 5$秒,大于等于$C$,所以他得到一颗糖果。
因此,他得到了三颗糖果。
样本输入2
3 2 0 2 4
样本输出2
3
样本输入3
10 3 0 3 4 6 9 12 15 17 19 20
样本输出3
7