Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define MX 1e9+5
- int main()
- {
- int n,i,cnt=1,res=1;
- scanf("%d",&n);
- int ara[n+1],j;
- for(i=0;i<n;i++)scanf("%d",&ara[i]);
- sort(ara,ara+n);
- i=0,j=1;
- int x=ara[i];
- while(j<n)
- {
- if(ara[j]-x<=5)
- {
- cnt++;
- // cout<<ara[j]-x<<" "<<cnt<<endl;
- j++;
- }
- else
- {
- i++;
- cnt-=1;
- if(i==n)break;
- x=ara[i];
- }
- if(cnt>res)res=cnt;
- }
- printf("%d\n",res);
- }
Advertisement
Add Comment
Please, Sign In to add comment