Java K springen

class solution{
public static void main(String[]ar){
	Scanner in = new Scanner(System.in);
  	int k=in.nextInt();
  	int n=in.nextInt();
  	int ar[]=new int[n];
  		for(int i=0;i<n;i++){
    		ar[i]=in.nextInt();
    	}
  		int count=1,j=1,l=1,max=0,i;
  		while(l<n){
    		i=l;
          	count=1;
          	j=i;
          	while(i<n){
          		++j;
              	if(ar[j]-ar[i]>=k){
                	++count;
                  	i=j;
                }
            }
          	if(count>max){
            	max=count;
            }
          k++;
    	}
  		System.out.println(max);
	}
}
Selfish Sloth