Could anyone please suggest why the following code is failing dew test cases while other test cases are running fine? What exactly is being checked in test cases 7-14? They are failing.
/* package codechef; // don’t place package name! */
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scanner = new Scanner(System.in);
int noOfPotentialCustomers = 0;
noOfPotentialCustomers = scanner.nextInt();
if (noOfPotentialCustomers >= 1 && noOfPotentialCustomers <= 5000) {
long[] custRate = new long[noOfPotentialCustomers];
for (int i = 0; i < noOfPotentialCustomers; i++) {
custRate[i] = scanner.nextLong();
}
System.out.println(maxPrice(custRate));
}
scanner.close();
}
private static long maxPrice(long[] custRate) {
Arrays.parallelSort(custRate);
long maxprice = 0;
for (int i = 0, k = custRate.length; i < custRate.length && k > 0; i++, k--) {
long max = custRate[i] * k;
if (max > maxprice)
maxprice = max;
}
return maxprice;
}
}