For this Question: You are given an array of length N and an integer K. The array will contain integers numbered through 1 to K. Your task is to calculate the maximum length of the subarray containing  not more than K-1 distinct numbers(atleast one number which does not occur in the subarray)The first line  contains two integers N and K
The second line contains N space-separated integers 

Constraints

1<=K , N<=100000
1<=A[I]<=100000Print a single line containing one integer ― the maximum length of a valid subsegment.Sample Input
6 2
1 1 1 2 2 1


Sample output:-
3


Sample Input:-
5 3
1 1 2 2 1


Sample Output:-
5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){

    int t;
    t=1;
    while(t--){
        long n,k;
        cin>>n>>k;
        long a[n];
        long sum=0,b[n];
        for(long i=0;i<n;i++){cin>>a[i];sum+=a[i];b[i]=sum;}
        int cnt[k+1];
        for(int i=0;i<=k;i++){cnt[i]=0;}
        long  x=0;
        int ans=0;
      	map<int,int> mp;
	int diff = 0;
	for(int i=0, l=0, r=0; i<n; i++)
	{
		if(mp[a[i]] == 0) diff++;
		mp[a[i]]++;
		if(diff == k)
		{
			while(diff == k)
			{
				mp[a[l]]--;
				if(mp[a[l]] == 0) diff--;
				l++;
			}
		}
		ans = max(ans, i -l + 1);
	}
	cout<<ans<<endl;
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?