ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov! B.Nastya and Door

2020-04-25 20:01:15  阅读:311  来源: 互联网

标签:pre mountains Door int number door Nastya Belonogov


Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov! B.Nastya and Door

题目链接
On February 14, Denis decided to give a Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k≥3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.

Mountains are described by a sequence of heights a1,a2,…,an in order from left to right (k≤n). It is guaranteed that neighboring heights are not equal to each other (that is, ai≠ai+1 for all i from 1 to n−1).

Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l<i<r, ai−1ai+1. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3,6].

To break the door, Nastya throws it to a segment [l,l+k−1] of consecutive mountains of length k (1≤l≤n−k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k−1].

Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l,l+k−1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal.

Formally, you need to choose a segment of mountains [l,l+k−1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l.

Input

The first line contains an integer t (1≤t≤104) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains two integers n and k (3≤k≤n≤2⋅105) — the number of mountains and the length of the door.

The second line of the input data set contains n integers a1,a2,…,an (0≤ai≤109, ai≠ai+1) — the heights of mountains.

It is guaranteed that the sum of n over all the test cases will not exceed 2⋅105.

Output

For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to.

Example

input

5
8 6
1 2 4 1 2 4 1 2
5 3
3 2 3 2 1
10 4
4 3 4 3 2 3 2 1 0 1
15 7
3 7 4 8 2 3 4 5 21 2 3 4 2 1 3
7 5
1 2 3 4 5 6 1

output

3 2
2 2
2 1
3 1
2 3

很明显的后缀和问题~
我们用 pre[i]pre[i]pre[i] 表示从当前位置到最后位置的山峰的数量,那么对当前位置 iii,在 [i,i+k1][i,i+k-1][i,i+k−1] 范围中山峰的数量就为 pre[i+k]pre[i]pre[i+k]-pre[i]pre[i+k]−pre[i],此时已经对了一大半了,题目要求边界不做考虑,所以我们还要标记一下,减去边界即可。对了,这题有个坑点,输出的位置要初始化为1,否则会WA,估计是有没有山峰的数据,真的无语(ˉ▽ˉ;)…,AC代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int t,n,k;
    cin>>t;
    while(t--){
        cin>>n>>k;
        int a[n+1],pre[n+k+2]={0};
        map<int,int>m;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=2;i<=n-1;i++){
            if(a[i]>a[i-1] && a[i]>a[i+1]){
                m[i]=1;
                pre[i]=1;
            }
        }
        for(int i=n+k;i>=1;i--){
            pre[i]+=pre[i+1];
        }
        int minpos=1,maxnum=0;
        for(int i=1;i<=n;i++){
            int p=pre[i]-pre[i+k]-m[i]-m[i+k-1];
            if(p>maxnum){
                maxnum=p;
                minpos=i;
            }
        }
        cout<<maxnum+1<<" "<<minpos<<endl;
    }
    return 0;
}

标签:pre,mountains,Door,int,number,door,Nastya,Belonogov
来源: https://blog.csdn.net/qq_43765333/article/details/105722719

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有