jakaria_hossain

codechef - coronavirous spread

May 2nd, 2020
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. #define ll long long
  5. int main()
  6. {
  7.     fastread()
  8.     ll t;
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         ll n,cnt, mn, mx, i;
  13.         cin>>n;
  14.         ll ara[n+1];
  15.         for(i=0; i<n; i++)
  16.             cin>>ara[i];
  17.         sort(ara,ara+n);
  18.         mx=0,mn=1e9,cnt=0;
  19.         for(i=0; i<n-1; i++)
  20.         {
  21.             if(abs(ara[i]-ara[i+1])<3)
  22.             {
  23.                 cnt++;
  24.             }
  25.             else
  26.             {
  27.                 mn=min(cnt,mn);
  28.                 mx=max(mx,cnt);
  29.                 cnt = 0;
  30.             }
  31.         }
  32.         mn=min(cnt,mn);
  33.         mx=max(mx,cnt);
  34.         cout<<mn+1<<" "<<mx+1<<endl;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment