#6 Div2 E. Exposition(RMQ+最长连续子序列变形)

网友投稿 368 2022-08-27

#6 Div2 E. Exposition(RMQ+最长连续子序列变形)

​​Exposition

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 kmillimeters.

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

In each of the following b

Examples

input

3 314 12 10

output

2 21 22 3

input

2 010 10

output

2 11 2

input

4 58 19 10 13

output

2 13 4

题意:额,就是让你求最长连续子序列,规定这个序列中的最大值和最小值相差不能超过K。

问你最长是多少。有多少个最长?并要求把它们的区间下标输出。

题解:用multiset保存这些数前缀,然后一个区间一个区间得check,不适合的小范围对于大范围也肯定不适合,可以把这个数删了,然后不断进行RMQ就可以了。

AC代码:

#includeusing namespace std;int a[100010];int n,k;vector>vp;multisets; int main(){ cin>>n>>k; for(int i=0;i>a[i]; int j=0; int ans = -1; for(int i=0;ik) s.erase(s.find(a[j++])); if(i-j+1>ans) { ans=i-j+1; vp.clear(); //要求vp坐标是最大的,注意将前面的清空 } if(i-j+1==ans)//记录新的最大和之后同等最大的坐标 { vp.push_back(make_pair(j+1,i+1)); } } cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Problem S4: Interesting Numbers 加强版 (数论)
下一篇:面对经济衰退期的营销红利,企业如何建设品牌!(品牌营销的发展)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~