E. Exposition
2 seconds
64 megabytes
standard input
standard output
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.
The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.
The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.
In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters.
In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.
3 3
14 12 10
2 2
1 2
2 3
2 0
10 10
2 1
1 2
4 5
8 19 10 13
2 1
3 4
#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;
int a[],c[];
int main()
{
int n,k,i,b=,max=,p=;
scanf("%d%d",&n,&k);
multiset<int> z;
for(i=; i<n; i++)
{
scanf("%d",&a[i]);
z.insert(a[i]);
while(*z.rbegin()-*z.begin()>k)z.erase(z.find(a[b++]));
if(i-b+>max)
{
max=i-b+,p=;c[p++]=b;
}
else if(i-b+==max)
{
c[p++]=b;
}
}
cout<<max<<" "<<p<<endl;
for(i=; i<p; i++)
printf("%d %d\n",c[i]+,c[i]+max);
}
E. Exposition的更多相关文章
- Codeforces Beta Round #6 (Div. 2 Only) E. Exposition multiset
E. Exposition Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/ ...
- A - Exposition CodeForces - 6E
题目链接:https://vjudge.net/contest/202699#problem/A 题意 给一个n个元素的序列,从中挑出最长的子序列,要求子序列中元素差的最大值不超过k.问有几个最长子序 ...
- Codeforces - 6E - Exposition - 尺取
https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...
- ECMAScript 6 Features 中文版
ECMAScript 6 Features 中文版 如词不达意,欢迎提 PR & issue 采用中英混排的方式进行译制,如不解请查看对应原文 本文档将与原作者的 文档 保持同步更新,欢迎关注 ...
- Back-propagation, an introduction
About Contact Subscribe Back-propagation, an introduction Sanjeev Arora and Tengyu Ma • Dec 20, ...
- 【转】关于KDD Cup '99 数据集的警告,希望从事相关工作的伙伴注意
Features From: Terry Brugger Date: 15 Sep 2007 Subject: KDD Cup '99 dataset (Network Intrusion) cons ...
- boost(barrier)
barrier:栅栏的意思,当barrier bar(3),这三个线程会放到栅栏中,等第三个线程执行时一起唤醒,然后返回 barrier barrier类的接口定义如下: class barrier ...
- Hacker's guide to Neural Networks
Hacker's guide to Neural Networks Hi there, I'm a CS PhD student at Stanford. I've worked on Deep Le ...
- PyOpenGL利用文泉驿正黑字体显示中文字体
摘要:在NeHe的OpenGL教程第43课源代码基础上,调用文泉驿正黑字体实现中文字体的显示 在OpenGL中显示汉字一直是个麻烦的事情,很多中文书籍的文抄公乐此不疲地介绍各种方法及其在windows ...
随机推荐
- 高性能消息队列 CKafka 核心原理介绍(上)
欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:闫燕飞 1.背景 Ckafka是基础架构部开发的高性能.高可用消息中间件,其主要用于消息传输.网站活动追踪.运营监控.日志聚合.流式 ...
- 10 Logistic Regression
线性分类中的是非题 --->概率题 (设置概率阈值后,大于等于该值的为O,小于改值的为X) --->逻辑回归 O为1,X为0 逻辑回归假设 逻辑函数/S型函数:光滑,单调 自变量趋于负无穷 ...
- Web in Linux小笔记001
Linux灾难恢复: Root密码修复 Centos single Filesystem是硬盘文件根目录,无法再cd ..就像macitosh 硬盘图标 Pwd:显示绝对路径 MBR修复 模拟MBR被 ...
- 【1414软工助教】团队作业4——第一次项目冲刺(Alpha版本) 得分榜
题目 团队作业4--第一次项目冲刺(Alpha版本) 作业提交情况情况 所有团队都在规定时间内完成了七次冲刺. 往期成绩 个人作业1:四则运算控制台 结对项目1:GUI 个人作业2:案例分析 结对项目 ...
- 201521123118《java程序设计》第一周学习总结
1. 本周学习总结 根据学习的过程中,虽然听学习过的人说过,c语言和java语言差不多,学习过c语言 在学java会比较容易,但是这一周发现,java和c还是有一些差别的: java语言是面向对象的语 ...
- 201521123078 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 1.互斥访问与同步访问 1.1 除了使用synchronized修饰方法实现互斥同步访问,还有什么 ...
- 201521123026 《java程序设计》 第九周学习总结
1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 Q1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) PTA提交结果: 运行结果截图: 1.2 ...
- Mysql数据库文件、表、记录的增删改查
一.数据库文件夹的的操作 create database db1 charset utf8; 增加db1文件夹 show databases ; 查看所有数据库 show create databas ...
- C#参数详解
参数 可选参数与命名参数 设计方法时,我们可以为部分参数设置默认值,在方法调用时就可以不提供该参数,使用其默认值.此外,调用方法时可以通过指定参数名的方式来传递参数.话不多说,请看以下示例: stat ...
- Myeclipse黑色主题配置
Myeclipse自己打造黑色主题: 一.UI Theme(设置黑色主题模式): 如果是自己下载在的.jar主题,则首先将该jar包放在Myeclipse安装目录下的\dropins\plugins\ ...