From heaven to earth Improvement

Hello, I recently posted asking some questions about From Heaven to Earth and the workings of codechef and what they look for specifically. Now that i’ve submitted my first accepted code I was looking for some insight on improving it. Here is the code:

public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int t = input.nextInt();

		while(t>0) {
		int n = input.nextInt();
		int v1 = input.nextInt();
		int v2 = input.nextInt();
		double t1 = (1.0*Math.sqrt(2)*n)/v1;
		double t2 = (1.0*2*n)/v2;
		if(t1 < t2){
		    System.out.println("Stairs");}
		else {
		    System.out.println("Elevator");}
		t--; }}}

Anything more i need to do for a small problem like this?

1 Like

It looks good. But you are using Scanner. This problem had small input-output, so you got an AC. But for large Inputs, Scanner itself more than 70% of time just for input output. (With scanner, one code with 4sec limit for JAVA took 3.4 sec just for input!!). You are risking a TLE, because if problem is needs a good deal of operations and computations, then it wont be able to do it if taking input takes more than half of the time limit.

2 Likes

What would be a better option for input? Also, what is a TLE?

TLE= Time Limit Exceed- When your program takes more time than the time limit to produce output.

Better option, try buffered reader. Although best option is to use fast input output template. google it, and then copy paste it in your ide and set it as your default template.

1 Like

Is it much more complex than just using a generic scanner?

A bit. Try googling yourself and see how it appears to you.