CSU - 2062 Z‘s Array

本文介绍了一种特殊的数组——m-peek数组,并提供了一个算法来判断一个给定的整数数组是否符合m-peek数组的标准。m-peek数组是指数组中恰好包含m个峰值元素的数组,峰值元素是指大于其相邻元素的数组项。通过遍历数组并计算峰值数量,可以确定该数组是否为m-peek数组。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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");
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值