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 ...
随机推荐
- [js高手之路]设计模式系列课程-组合模式+寄生组合继承实战新闻列表
所谓组合模式,就是把一堆结构分解出来,组成在一起,现实中很多这样的例子,如: 1.肯德基套餐就是一种组合模式, 比如鸡腿堡套餐,一般是是由一个鸡腿堡,一包薯条,一杯可乐等组成的 2.组装的台式机同理, ...
- spring mvc:@RequestParam与@ModelAttribute异同
关于spring mvc中的两个注解:@RequestParam.@ModelAttribute区别,原先并没有特别注意,直到最近找别人开发的一个小模块的bug时,才有意识的比较了两者的区别. 1.@ ...
- C语言中复数运算及调用blas,lapack中复数函数进行科学计算
C语言中常用的数据类型主要int, float ,double ,char 等,但在科学运算中复数扮演着重要角色.这里讲下C语言中的复数运算以及如何调用blas,lapack库中的复数函数来进行科学计 ...
- 浅谈一下Java String
相信很多同学使用Java String, Java中的String方法,但是对其中的原理可能有些模糊,那么咱们就针对这块内容进行展开,让更多的同学理解和知道. public final class S ...
- Swing-setMaximumSize()用法-入门
与setMinimumSize()一同讨论.顾名思义,这两个函数用于设置窗体的最大.最小值.然而测试发现,setMaximumSize()直接作用于JFrame时,无法实现其预定功能,setMinim ...
- 201521123122 《java程序设计》 第六周实验总结
201521123122 <java程序设计>第六周实验总结 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想 ...
- 201521123015 《Java程序设计》第3周学习总结
本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点. 书面作业 Q1.代码阅读 publi ...
- 第2周作业-Java基本语法与类库(20170227-20170304)
本周学习总结 (1)这周学习认识和熟悉了java的一些类型和变量: (2)学习了java的运算符基本使用方法: (3)了解了如何建立远程仓库和本地仓库,和如何让java代码在临时储存,本地仓库和远程仓 ...
- 201521123080《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 多线程: 操作系统有两个容易混淆的概念,进程和线程. 进程:一个计算机程序的运行实例,包含了需要执行的指令:有自己 ...
- panda库------对数据进行操作---合并,转换,拼接
>>> frame2 addr age name 0 beijing 12 zhang 1 shanghai 24 li 2 hangzhou 24 cao >>> ...