5.20 Vj F - Nastya and Door
#include<bits/stdc++.h>
#define ll long long
using namespace std;
//题意是给你n个数,让你在其中找一串长度为k的数的最左端,使这段k中山峰数最多,并求最多的山峰数
int main( )
{
int t;
cin>>t;
while(t--)
{
int n,k,r=1,maxx=0,res=0;
cin>>n>>k;
int a[n+2],b[n+2];
for(int i=0; i<n; i++)
{
cin>>a[i];
if(i>=2&&a[i-1]>a[i-2]&&a[i-1]>a[i])
{
res++;
}
b[i]=res;//记录山峰的下标
}
// 1 2 4 1 2 4 1 2
//res 0 0 1 1 1 2 2 2
for(int i=0; i+k-1<n; i++)
{
if(maxx<b[i+k-1]-b[i+1])//找出k段中山峰所在位置
{
r=i+1;
}
maxx=max(maxx,b[i+k-1]-b[i+1]);
}
cout<<maxx+1<<" "<<r<<endl;
}
#define ll long long
using namespace std;
//题意是给你n个数,让你在其中找一串长度为k的数的最左端,使这段k中山峰数最多,并求最多的山峰数
int main( )
{
int t;
cin>>t;
while(t--)
{
int n,k,r=1,maxx=0,res=0;
cin>>n>>k;
int a[n+2],b[n+2];
for(int i=0; i<n; i++)
{
cin>>a[i];
if(i>=2&&a[i-1]>a[i-2]&&a[i-1]>a[i])
{
res++;
}
b[i]=res;//记录山峰的下标
}
// 1 2 4 1 2 4 1 2
//res 0 0 1 1 1 2 2 2
for(int i=0; i+k-1<n; i++)
{
if(maxx<b[i+k-1]-b[i+1])//找出k段中山峰所在位置
{
r=i+1;
}
maxx=max(maxx,b[i+k-1]-b[i+1]);
}
cout<<maxx+1<<" "<<r<<endl;
}
return 0;
}
}

浙公网安备 33010602011771号