jakaria_hossain

codeforce - Balanced Team

Mar 7th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define MX 1e9+5
  5. int main()
  6. {
  7. int n,i,cnt=1,res=1;
  8. scanf("%d",&n);
  9. int ara[n+1],j;
  10. for(i=0;i<n;i++)scanf("%d",&ara[i]);
  11. sort(ara,ara+n);
  12. i=0,j=1;
  13. int x=ara[i];
  14. while(j<n)
  15. {
  16. if(ara[j]-x<=5)
  17. {
  18. cnt++;
  19.  
  20. // cout<<ara[j]-x<<" "<<cnt<<endl;
  21. j++;
  22. }
  23. else
  24. {
  25. i++;
  26.  
  27. cnt-=1;
  28. if(i==n)break;
  29. x=ara[i];
  30. }
  31. if(cnt>res)res=cnt;
  32. }
  33. printf("%d\n",res);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment