Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int maxCount(int n,int a[])
- {
- map<int,int> freq;
- for(int i=0; i<n; ++i)
- {
- if(freq[a[i]])
- freq[a[i]] += 1;
- else
- freq[a[i]] = 1;
- }
- int ans = 0, key;
- map<int,int>:: iterator it=freq.begin();
- while(it!=freq.end())
- {
- key = it->first;
- ++it;
- if(freq[key+1]!=0)
- ans=max(ans,freq[key]+freq[key+1]);
- }
- return ans;
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- int a[10005];
- for(int i=0; i<n; i++)
- {
- cin>>a[i];
- }
- cout<<maxCount(n,a)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment