Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- using namespace std;
- int main()
- {
- int n,k;
- cin>>n>>k;
- int x[n];
- map<int,int>mapa;
- map<int,int>cnt;
- for(int i=0;i<n;i++)
- {
- cin>>x[i];
- }
- int kn[k];
- for(int i=0;i<k;i++)
- {
- cin>>kn[i];
- mapa[kn[i]]++;
- }
- multiset<int>ms;
- for(int i = 0; i < k; i++) {
- ms.insert(0);
- }
- int ans=0;
- int i=0,j=0;
- while(j<n)
- {
- if(*ms.begin()<=3 && *ms.rbegin()<=3)
- {
- if(mapa[x[j]]==1)
- {
- ms.erase(ms.find(cnt[x[j]]));
- cnt[x[j]]++;
- ms.insert(cnt[x[j]]);
- }
- if(*ms.begin()==3 && *ms.rbegin()==3)
- {
- ans=max(ans, j-i+1);
- }
- j++;
- }else
- {
- if(mapa[x[i]]==1)
- {
- ms.erase(ms.find(cnt[x[i]]));
- cnt[x[i]]--;
- ms.insert(cnt[x[i]]);
- }
- i++;
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement