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

time complexity ..in int and long (java)..plz help

$
0
0
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
public class TurboSort3 {

    public static void main(String args[]) throws IOException {
        BufferedReader br= new BufferedReader( new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(
                new BufferedWriter(
                        new OutputStreamWriter(System.out)));
        String s= br.readLine();
        Integer test = Integer.parseInt(s); 
        long[] c= new long[test];
        int i=0;
        while(test>0) {
            int n = Integer.parseInt(br.readLine());
            c[i]=n;
            i++;
            test--;
        }

    Arrays.sort(c);

        for(int j=0;j<c.length;j++){
            pw.println(c[j]);
            }

        pw.close();

        }

}

This code takes time=5.29sec...and when I am using "int" instead of 'long' for the array 'c'..that takes time = 10.01 sec.......why is it taking different time reading 'long' and 'int'..?? plz explain..


Viewing all articles
Browse latest Browse all 39796

Trending Articles



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