zoukankan      html  css  js  c++  java
  • codeforces 6E (非原创)

    E. Exposition
    time limit per test
    1.5 seconds
    memory limit per test
    64 megabytes
    input
    standard input
    output
    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.

    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.

    Examples
    Input
    3 3
    14 12 10
    Output
    2 2
    1 2
    2 3
    Input
    2 0
    10 10
    Output
    2 1
    1 2
    Input
    4 5
    8 19 10 13
    Output
    2 1
    3 4

    这道题我搞了两天,为此学了好多东西,还没有消化。(线段树的查询那部分我不太理解,二分搜索真是智商搜索。。

    附本人学习此题解法的博客:http://blog.csdn.net/acmer_hades/article/details/49025845

  • 相关阅读:
    冒泡排序法
    冒泡排序法
    【HAOI2008】圆上的整点
    2018年全国多校算法寒假训练营练习比赛(第四场)F:Call to your teacher
    (java)Jsoup爬虫学习--获取网页所有的图片,链接和其他信息,并检查url和文本信息
    CSS 选择器
    (java)selenium webdriver学习---实现简单的翻页,将页面内容的标题和标题链接取出
    (java)selenium webdriver学习---三种等待时间方法:显式等待,隐式等待,强制等待
    使用D3绘制图表(5)--水平柱状图表
    使用D3绘制图表(4)--面积图表
  • 原文地址:https://www.cnblogs.com/zmin/p/7821773.html
Copyright © 2011-2022 走看看