Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- map<int,int>mp;
- int cnt=0;
- void del(int x)
- {
- mp[x]--;
- if(mp[x]==0)
- cnt--;
- }
- void add(int x)
- {
- mp[x]++;
- if(mp[x]==1)
- cnt++;
- }
- int main()
- {
- int n,k;
- cin>>n>>k;
- int ara[n+1],i,j,cmp=0,l,r;
- for(i=0; i<n; i++)
- cin>>ara[i];
- i=0;
- j=0;
- cnt=0;
- while(j<n)
- {
- if(cnt<=k)
- {
- add(ara[j]);
- }
- if(cnt>k)
- {
- del(ara[i]);
- i++;
- }
- if(cnt<=k)
- {
- if(cmp<=j-i)
- {
- cmp=j-i;
- l=i+1;
- r=j+1;
- }
- j++;
- }
- }
- cout<<l<< " "<<r<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement