cf

Problem - C - Codeforces

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+8;
using ll=long long;
int t,n,k,c[N];
void solve()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>c[i];
	//首尾相同 一块区域
	if(c[0]==c[n-1])
	{
		if((count(c,c+n,c[0]))>=k)//如果第一个数的个数>=k
			cout<<"YES";
		else
			cout<<"NO";
		return ;
	}
	//不同 分俩块区域 开头颜色和末尾颜色
	int cnt1=count(c,c+n,c[n-1]); //先统计最后一个数的个数
	int cnt2=0;
	for(int i=0;i<n;i++)
	{
		cnt2+=(c[0]==c[i]);  //如果c[0]==c[i] cnt2++
		cnt1-=(c[n-1]==c[i]); //此时cnt1表示在第i位置往后有多少个c[n-1]
		if(cnt1>=k&&cnt2>=k)
		{
			cout<<"YES";
			return ;
		}
	}
	cout<<"NO";
}
int main()
{
	cin>>t;
	while(t--)
	{
		solve();
		cout<<endl;
	}
	return 0;
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值