Problem link-https://www.codechef.com/TSCO2017/problems/TSECJ106
solution-
import java.util.Arrays; import java.util.Scanner;
/ * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor./
//package codechef;
/ * @author DELL/ public class rods { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int cnt=1;
int maintain=0;
Arrays.sort(a);
for(int i=0;i<n;i++)
{
if(i==0)
maintain=(a[i]+6);
else
{
if(a[i]>maintain)
{
maintain=a[i]+6;
cnt++;
}
}
}
System.out.println(cnt);
}
}