A10663 | Crazy Computer
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
ZS the Coder is coding on a crazy computer. If you don't type in a word for a $c$ consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second $a$ and then the next word at second $b$ , then if $b-a<=c$ , just the new word is appended to other words on the screen. If $b-a>c$ , then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if $c=5$ and you typed words at seconds $1,3,8,14,19,20$ then at the second $8$ there will be $3$ words on the screen. After that, everything disappears at the second $13$ because nothing was typed. At the seconds $14$ and $19$ another two words are typed, and finally, at the second $20$ , one more word is typed, and a total of $3$ words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
More formally, if you typed a word at second $a$ and then the next word at second $b$ , then if $b-a<=c$ , just the new word is appended to other words on the screen. If $b-a>c$ , then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if $c=5$ and you typed words at seconds $1,3,8,14,19,20$ then at the second $8$ there will be $3$ words on the screen. After that, everything disappears at the second $13$ because nothing was typed. At the seconds $14$ and $19$ another two words are typed, and finally, at the second $20$ , one more word is typed, and a total of $3$ words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
输入格式
The first line contains two integers $n$ and $c$ ( $1<=n<=100000,1<=c<=10^{9}$ ) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains $n$ integers $t_{1},t_{2},...,t_{n}$ ( $1<=t_{1}<t_{2}<...<t_{n}<=10^{9}$ ), where $t_{i}$ denotes the second when ZS the Coder typed the $i$ -th word.
The next line contains $n$ integers $t_{1},t_{2},...,t_{n}$ ( $1<=t_{1}<t_{2}<...<t_{n}<=10^{9}$ ), where $t_{i}$ denotes the second when ZS the Coder typed the $i$ -th word.
输出格式
Print a single positive integer, the number of words that remain on the screen after all $n$ words was typed, in other words, at the second $t_{n}$ .
输入输出样例
输入 #1
6 5 1 3 8 14 19 20
输出 #1
3
输入 #2
6 1 1 3 5 7 9 10
输出 #2
2
The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second $1$ , it disappears because the next word is typed at the second $3$ and $3-1>1$ . Similarly, only $1$ word will remain at the second $9$ . Then, a word is typed at the second $10$ , so there will be two words on the screen, as the old word won't disappear because $10-9<=1$ .
For the second sample, after typing the first word at the second $1$ , it disappears because the next word is typed at the second $3$ and $3-1>1$ . Similarly, only $1$ word will remain at the second $9$ . Then, a word is typed at the second $10$ , so there will be two words on the screen, as the old word won't disappear because $10-9<=1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted