Smartphone ZCO

Could someone please tell me what is wrong with this code? It shows wrong answer for some test cases, and is there any way to see what input failed?
thanks.

import java.util.*;

public class smartphonezco{

public static void main(String args[]) {

Scanner obj = new Scanner(System.in);

int i,n,max;

System.out.println("enter total number of customers: ");

n = obj.nextInt();

int b[] = new int [n];

int sum[] = new int[n];

for ( i=0;i<n;i++)

{

b[i] = obj.nextInt();

}

Arrays.sort(b);

for ( i =0;i<n;i++)

{

sum[i] = b[i] * (n-i);

}

max = sum[0];

for (i=1;i<n;i++)

{

if (sum[i] >max)

max = sum[i];

}

System.out.println(max);

}

}

System.out.println("enter total number of customers: ");

Remove this line. It should work after that. You can’t have any extra output in any program until mentioned so. That extra output will lead to WA.

It still does not work though . @aryan12

Hey @shubh2003, the question itself states that you should use variables of type long, and not type int. In your program, you may encounter test cases with a value > Integer.MAX_VALUE. If you use long instead of int, it should work.

It worked, thanks a lot! @godlysk

You’re welcome :slight_smile:

True, didn’t see that pointer.