Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a cconsecutive 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 3words 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.
Input
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where tidenotes the second when ZS the Coder typed the i-th word.
Output
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 tn.
Example
6 5
1 3 8 14 19 20
3
6 1
1 3 5 7 9 10
2
Note
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.
时间间隔超过c就会清除,问最后剩下几个数。 代码:
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int n,c;
cin>>n>>c;
int d;
if(n)cin>>d;
int t = d;
int counti = ;
for(int i = ;i < n;i ++)
{
cin>>d;
if(d - t > c)counti = ;
else counti ++;
t = d;
}
cout<<counti;
}
Crazy Computer的更多相关文章
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- CodeForces 716A Crazy Computer
题目链接:http://codeforces.com/problemset/problem/716/A 题目大意: 输入 n c, 第二行 n 个整数,c表示时间间隔 秒. 每个整数代表是第几秒.如果 ...
- CF716A Crazy Computer 题解
Content 有一个电脑,如果过了 \(c\) 秒之后还没有任何打字符的操作,就把屏幕上面所有的字符清空.现在,给定 \(n\) 次打字符的时间 \(t_1,t_2,...,t_n\),求最后屏幕剩 ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- Codeforces Round #372 (Div. 2) A
Description ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecut ...
- Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #372 +#373 部分题解
用了两场比赛上Div 1感觉自己好腊鸡的说...以下是这两场比赛的部分题解(不得不说有个黄学长来抱大腿还是非常爽的) Round #372 : Div 2 A:Crazy Computer 题意:给定 ...
随机推荐
- 554C - Kyoya and Colored Balls
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
- Ubuntu安装NVIDA显卡驱动
0. 综述 电脑型号:R720 Ubuntu版本:16 显卡型号:1050ti 目前,知道3种安装N卡驱动的方法: 1. PPA源:最简便,但未必有最新驱动(亲测),或可能遇到问题(风闻). sudo ...
- Asp.Net MVC中Action跳转
首先action的跳转大致归类: 1跳转到与当前同一控制器内的action和不同控制器内的action. 2带有参数的action跳转和不带参数的action跳转. 3跳转到指定视图,不经过Contr ...
- 常用HTTP contentType与后端处理方式
常用HTTP contentType与后端处理方式 1.Content-Type:application/x-www-form-urlencoded; charset=UTF-8 前端export.j ...
- ArcGIS 要素闪烁
ArcGIS 要素闪烁 通过双击要素图例,闪烁定位到要素,并且闪烁一段时间: IFeatureLayer featureLayer = layer as IFeatureLayer; ...
- English trip -- VC(情景课) 6 B Events 事件
xu言: ... 自己选择的路,就算是爬,也要给我爬完.短短人生数载,我能之止于此? Words appointment 预约 meeting 会议 class movie party prog ...
- LeetCode--176--第二高的薪水
问题描述: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 ...
- 3-5 回顾,快速二分法的疑点解惑:为啥先右j移动?因为设定a[left]为基准点
快速二分法的疑点解惑:为啥先右j移动?因为设定a[left]为基准数 , 1] [91, 86, 42, 46, 9, 68, 77, 46, 7, 1] [91, 86, 42, 46, 9, 68 ...
- 『Collections』Counter计数
Counter()方法 计数器,返回字典,会同时去重,文本处理常用 from collections import Counter co = Counter(list('abcdefgad')) co ...
- hdu1238 kmp
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...