Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

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

$
0
0

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

      }

}


Viewing all articles
Browse latest Browse all 39796

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>