Doubt of choclate moger question

Problem Code: CM164364

For this ques why is my ans wrong…

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main(void)
{
	ll t,n,x,i,count=1,ans=0;
	int arr[100000];
	cin>>t;
	while(t--)
	{
	    ans=0;count=1;
	    cin>>n >> x;
	    for(i=0;i<n;i++)
	    {
	        cin>>arr[i];
	    }
	     for(i=0;i<n-1;i++)
	    {
	        if(arr[i]==arr[i+1])
	        {
	            count=count;
	        }
	        else
	        count++;
	    }
	   ans=n-x;
	    if(count>=ans)
	    cout<< ans <<endl;
	    else
	    cout << count<<endl;
	    
	}
		return 0;
}

Did you forget to sort the Array of Integers?

2 Likes

yeah, as @suman_18733097 said you need to sort the array as the type of chocolates may be shuffled.

OK thanks guyss…