Description
Z likes to play with array. One day his teacher gave him an array of n elements, and ask Z whether the array is a "m-peek" array.
A "m-peek" array is an array which has exactly m peek.
a term a[i] is called a peek if and only if a[i]>a[i − 1] and a[i]>a[i + 1]
If the array has exactly m peeks, the array is called a "m-peek" array.
Input
The first line is the case number T
each case has two integer n, m where n denotes the number of elements in the array
then followed by n 32-bit signed integers in the array.
1 ≤ T ≤ 100
1 ≤ n ≤ 1000000
0 ≤ m ≤ n
Output
For each case,
print a single word "Yes" without quotation when the array is a "m-peek" array.
print "No" without quotation otherwise.
Sample Input
2
5 1
5 7 11 2 1
4 1
4 5 5 6
Sample Output
Yes
No
Hint
Source
Author
#include<stdio.h>
#define MAXN 1000010
int a[MAXN];
int main()
{
int t, n, m;
while (~scanf("%d", &t))
{
while (t--)
{
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
int num = 0;
for (int i = 1; i < n-1; i++)
{
if (a[i] >a[i - 1] && a[i] > a[i + 1])
{
num++;
}
}
if (num == m)
printf("Yes\n");
else
printf("No\n");
}
}
}