my approach is correct or not for chef and rods of TSEC codeathon?

Problem link-https://www.codechef.com/TSCO2017/problems/TSECJ106

solution-

import java.util.Arrays;
import java.util.Scanner;

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);
      
      }

}

check this:
https://www.codechef.com/viewsolution/14712468

//