首页 > 其他 > 详细

B. Nastya and Door

时间:2020-04-25 19:19:10      阅读:117      评论:0      收藏:0      [点我收藏+]
PS:这次终于过了!!!一开始方法太复杂了,以后要学会中途换方法。以及太菜了要多练习qwq就是只说闲话就是不写题解不写题解
time limit per test:1 second
memory limit per test:256 megabytes
input
standard input
output
standard output

On February 14 Denis decided to give 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 (k3 ). 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 (kn ). It is guaranteed that neighboring heights are not equal to each other (that is, aiai+1 for all i from 1 to n1 ).

Peaks of mountains on the segment [l,r] (from l to r ) are called indexes ii such that l<i<rl<i<r , ai1<ai and ai>ai+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+k1] of consecutive mountains of length kk (1lnk+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 pp is the number of peaks on the segment [l,l+k1]

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 tt (1t104 )  — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains two integers nn and k (3kn2105 )  — the number of mountains and the length of the door.

The second line of the input data set contains n integers a1,a2,,an (0ai109 , aiai+1)  — the heights of mountains.

It is guaranteed that the sum of nn over all the test cases will not exceed 2105 .

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
Copy
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
Copy
3 2
2 2
2 1
3 1
2 3
Note

In the first example, you need to select a segment of mountains from 2 to 7 . In this segment, the indexes 33 and 66 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1,6] and [3,8] are not suitable since they only have a 1 peak (for the first segment, the 66 index is not a peak, and for the second segment, the 3 index is not a peak).

In the second example, you need to select a segment of mountains from 2 to 4 . In this segment, the index 33 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts).

In the third example, you need to select a segment of mountains from 1 to 4 . In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2,5] , [4,7] and [5,8] the number of peaks is also 1 , but these segments have a left border greater than the segment [1,4] , so they are not the correct answer.

 

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=2e5+5;
int a[N],c[N];

int main(){
ios::sync_with_stdio(0);
int t;
cin>>t;
while(t--){
    int n,k,pos=1,cnt=0,maxn=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i>=2&&a[i-2]<a[i-1]&&a[i]<a[i-1])
            cnt++;
            c[i]=cnt;
    }
    for(int i=0;i+k-1<n;i++){
        if(maxn<c[i+k-1]-c[i+1])
            pos=i+1;
        maxn=max(maxn,c[i+k-1]-c[i+1]);
    }
cout<<maxn+1<<‘ ‘<<pos<<endl;
}
return 0;
}

  

B. Nastya and Door

原文:https://www.cnblogs.com/asunayi/p/12774556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!