博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Beta Round #6 (Div. 2 Only) E. Exposition multiset
阅读量:6266 次
发布时间:2019-06-22

本文共 3604 字,大约阅读时间需要 12 分钟。

E. Exposition

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/problemset/problem/6/E

Description

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.

Input

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.

Output

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.

Sample Input

3 3

14 12 10

Sample Output

2 2

1 2
2 3

HINT

 

题意

给你一堆数,让你找到最长的区间,使得这个区间里面的最大值减去最小值不超过K,然后让你输出每一个区间的起始位置和结束为止

题解:

类似于双端队列的写法,我们用multiset来处理这个问题,如果当前区间不合法,那么我们不断删去起始端的数就好了

然后不断跑,O(n) 

代码

 

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 1000010#define mod 10007#define eps 1e-9int Num;char CH[20];//const int inf=0x7fffffff;const int inf=0x3f3f3f3f;/*inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}*/inline ll read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}//**************************************************************************************int a[maxn];vector< pair
> q;multiset
s;int main(){ int n=read(),k=read(); for(int i=0;i
k) s.erase(s.find(a[j++])); if(i-j+1>aa) { aa=i-j+1; q.clear(); } if(i-j+1==aa) q.push_back(make_pair(j+1,i+1)); } printf("%d %d\n",aa,q.size()); for(int i=0;i

 

转载地址:http://ozdpa.baihongyu.com/

你可能感兴趣的文章
JavaScript中call,apply,bind方法的区别
查看>>
js 回顾知识总结一
查看>>
centeros bash: ifconfig: command not found
查看>>
leetcode Invert Binary Tree
查看>>
Python Requests快速入门
查看>>
[转] Invoke and BeginInvoke
查看>>
DataFrame的基本操作
查看>>
mysql02
查看>>
linux lftp命令
查看>>
多继承同名隐藏举例
查看>>
sql server 数据库忘记sa账户密码/ 无管理员账户解决办法
查看>>
试玩 PHP 5.4 的新特性
查看>>
Word该值小于列表中的前一条目
查看>>
第九周项目7-趣味编程
查看>>
JavaScript 函数式编程中的 curry 实现
查看>>
21.4 windows_21_Library_use_DLL 动态库补充4
查看>>
查看Eclipse运行工程时使用的Command Line
查看>>
使用WinExec打开文件夹
查看>>
作业要求 20181009-9 每周例行报告
查看>>
Mininet添加iperfmulti功能
查看>>