Help me in solving NOBEL problem

My issue

Time Limit Exceeded with my code…

My code

#include <iostream>
using namespace std;

int ConsectutiveSum(int x){
    
    if (x == 1){
        return 1;
    }
    
    int ans = x + ConsectutiveSum(x-1);
    
    return ans;
}

int main() {
	// your code goes here
	int t;
	cin>>t;
	while (t--){
	    int N, M;
	    cin>>N>>M;
	    
	    int a[N];
	    for (int i = 0; i < N; i++){
	        cin>>a[i];
	    }
	    
	    for (int i = 0; i < N; i++){
	        for(int j = i+1; j < N; j++){
	            if (a[j] == a[i] && a[i] != 0){
	                a[j] = 0;
	            }
	        }
	    }
	    
	    int sum = 0;
	    for (int i = 0; i < N; i++){
	        sum += a[i];
	    }
	    
	    int K = ConsectutiveSum(M);
	    
	    
	    if (K == sum){
	        cout << "No" << endl;
	    }
	    else{
	        cout << "Yes" << endl;
	    }
	}
	return 0;
}

Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone

@aryav
your logic is not right
plzz refer my c++ solution
hope u will get it.

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,m;
	    cin>>n>>m;
	    int a[n];
	    set<int> s;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        s.insert(a[i]);
	    }
	    if(s.size()!=m)
	    cout<<"YES";
	    else
	    cout<<"NO";
	    cout<<endl;
	}
	return 0;
}