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