• (RMQ) cf 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.

    Sample test(s)
    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
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<set>
    using namespace std;
    multiset<int> s;
    int a[100100],c[100100],n,k,b,m,p;
    int main()
    {
          scanf("%d%d",&n,&k);
          for(int i=0;i<n;i++)
          {
              scanf("%d",&a[i]),s.insert(a[i]);
              while(*s.rbegin()-*s.begin()>k) s.erase(s.find(a[b++]));
              if(i-b+1==m) c[p++]=b;
              else if(i-b+1>m) c[0]=b,p=1,m=i-b+1;
          }
          printf("%d %d
    ",m,p);
          for(int i=0;i<p;i++)
          {
                printf("%d %d
    ",c[i]+1,c[i]+m);
          }
          return 0;
    }
    

      

      



  • 相关阅读:
    Asp.net性能优化总结(一)
    Visual C#常用函数和方法集汇总
    ASP.net下大文件上传的解决方案及WebbUpload组件源码
    正则表达式学习
    在Asp.net中为图像加入版权信息
    Cognos 维度函数
    Cognos8.3函数使用手册(二)
    cognos更新步聚
    Cognos8.3函数使用手册(一)
    Cognos 8 报表备份和恢复
  • 原文地址:https://www.cnblogs.com/a972290869/p/4251432.html
Copyright © 2020-2023  润新知